我想在我的三星galaxy tab10.1中创建像root / Myfolder一样的文件夹。我使用了Environment.getExternalStorageDirectory()但是它给了我mnt / sdcard而不是root /。任何人都知道如何获取我平板电脑根的路径?< / p>
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();
}
答案 0 :(得分:0)
尝试一下
File mydir = context.getDir("dir", Context.MODE_PRIVATE);
if(!mydir.exists)
{
mydir.mkdirs();
}
Add permission in android manifest file
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
或尝试
String path = Environment.getExternalStorageDirectory().getAbsolutePath()+"/MyPdf";
File dir = new File(path);
if (!dir.exists()){
dir.mkdirs();
}