【发布时间】:2013-11-21 05:01:47
【问题描述】:
我想在我的三星 Galaxy tab10.1 中创建文件夹,例如 root/Myfolder。我使用了 Environment.getExternalStorageDirectory(),但它给了我 mnt/sdcard 而不是 root/。有人知道如何获取我的平板电脑的根路径吗?
String extStorageDirectory = Environment.getExternalStorageDirectory().toString();
File folder = new File(extStorageDirectory+"/download/", "MyPdf");
// folder = new File("/root/download/", "MyPdf");
if(!folder.exists()) {
folder.mkdir();
}
File file = new File(folder, "Read.pdf");
try {
file.createNewFile();
} catch (IOException e1) {
e1.printStackTrace();
}
【问题讨论】:
-
将发布您尝试并检查 Android 清单文件写入权限的代码
-
String extStorageDirectory = Environment.getExternalStorageDirectory().toString();文件夹 = new File(extStorageDirectory+"/download/", "MyPdf"); //文件夹 = new File("/root/download/", "MyPdf"); if(!folder.exists()) { folder.mkdir(); } 文件文件 = 新文件(文件夹,“Read.pdf”);尝试 { file.createNewFile(); } catch (IOException e1) { e1.printStackTrace(); }
-
@nitishpatel 你想要哪个根路径?默认情况下,android 提供
mnt/..作为根路径。 AFAIK 没有其他方法可以获取根路径。 -
@GrIsHu 我想要 root/.. 作为根路径。我知道 mnt/.. 是默认的,但是对于 tab10.1,root/ 在那里。无论我在我的设备上有什么创建文件夹,但没有在我的 Tab10.1 上,因为 Tab 有 root/.. 作为主文件夹。
标签: android makefile directory android-file