问题描述
我已经尝试过此代码,但是它总是在手机的内存中创建一个文件夹。
String externalDataPath = Environment.getExternalStorageDirectory() + "/yourFolder";
File f = new File(externalDataPath);
try {
if (!f.exists()) {
f.mkdir();
}
externalDataPath = externalDataPath + "/" + filename;
f = new File(externalDataPath);
if (!f.exists())
f.createNewFile();
externalDataPath = Environment.getExternalStorageDirectory().toString();
} catch (IOException e) {
e.printStackTrace();
}
此外,我在清单文件中添加了 EXTERNAL_WRITE PERMISSION 。
任何帮助将不胜感激。
解决方法
通过使用返回的第二项,可以获取可移动Micro SD卡上应用程序特定文件夹的路径
getExternalFilesDirs()