2014-12-22 117 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我的回答:) –