2013-11-21 166 views
0

我想在我的三星galaxy tab10.1內創建文件夾,比如root/Myfolder.I使用Environment.getExternalStorageDirectory(),但它給了我mnt/sdcard不是root /。任何人都知道如何獲得我的平板電腦根目錄的路徑?如何在root /三星Galaxy Tab 10.1中創建文件夾?

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

會後的代碼爲u嘗試和檢查機器人MANIFEAST文件的寫權限 –

+0

字符串extStorageDirectory = Environment.getExternalStorageDirectory()的ToString(); 文件夾=新建文件(extStorageDirectory +「/ download /」,「MyPdf」); \t \t \t \t // File folder = new File(「/ root/download /」,「MyPdf」); \t \t如果 \t \t { \t \t folder.mkdir()(folder.exists()!); \t \t} \t \t File file = new File(folder,「Read.pdf」); \t \t嘗試{ \t \t file.createNewFile(); catch(IOException e1){ \t \t \t e1.printStackTrace(); \t \t} –

+0

@nitishpatel你想要的根路徑?默認情況下,android提供'mnt/..'作爲根路徑。 AFAIK沒有其他方法來獲取根路徑。 – GrIsHu

回答

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(); 
} 
相關問題