2014-12-22 184 views
0

我想創建一個目錄和代碼運行而不引發異常,但目錄沒有創建(使用Mac上的Android文件傳輸應用程序進行檢查)。日誌中沒有條目。這裏出了什麼問題? 權限到位目錄沒有創建

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> 

<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE"/> 

下面的代碼:

File path = getFilesDir(); 

    File filenew = null; 

    try { 
     filenew= new File(path+"/equation"); 
     filenew.mkdirs(); 

    } catch (Exception e) { 
     e.printStackTrace(); 
    } 
+0

getFilesDir()「的getPath +。 /等式「 –

+0

可能du plicate [如何在Android中創建目錄?](http://stackoverflow.com/questions/4776426/how-to-create-a-directory-in-android) – duggu

+0

嘗試'File filenew = new File(getFilesDir( ),「equation」);)filenew.mkdirs()' –

回答

1

試試這樣說:

String externalDirectory= Environment.getExternalStorageDirectory().toString(); 
File folder= new File(externalDirectory + "/NewFolder"); 
folder.mkdir(); 
1

試試這個

File root = new File(Environment.getExternalStorageDirectory(), "/MYFOLDER"); 
      if(!root.exists()){ 
       root.mkdirs(); 
       } 
+0

沒有工作。奇怪的是,當我做 filenew = new File(Environment.getExternalStorageDirectory(),「equation」)時,我的變量filenew包含/ storage/emulated/0/equation。 filenew.mkdirs(); – michaelsmith

+0

我重新啓動設備,現在目錄在那裏。奇怪... – michaelsmith

+0

其工作手段。 Upvote我的回答:) –