【问题标题】:How to create folder inside root/ of samsung galaxy tab 10.1?如何在三星 Galaxy Tab 10.1 的根目录下创建文件夹?
【发布时间】: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


【解决方案1】:

试试看

 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();
}

【讨论】:

    猜你喜欢
    • 2012-07-31
    • 1970-01-01
    • 2014-01-10
    • 2012-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-21
    • 2013-02-14
    相关资源
    最近更新 更多