2012-09-30 70 views
0
File dir = Environment.getExternalStorageDirectory(); 
     if (dir.exists() && dir.isDirectory()) { 
      String exStoragePath = Environment.getExternalStorageDirectory().getAbsolutePath(); 
      File appPath = new File(exStoragePath + "/mbrc/"); 
      appPath.mkdirs(); 
      String tempFilename = "tmp.wav"; 
      String tempDestFile = appPath.getAbsolutePath() + "/" + tempFilename; 

      return tempDestFile; 
     } 

我在Android 2.2上嘗試使用HTC,但目錄沒有創建,文件也沒有。如果我在SAMSUNG S2上嘗試這個wuth android 4然後工作。如何在Android 2.2中的mnt/sdcard中創建目錄

爲什麼這不適用於HTC和android 2.2?

回答

1

您需要創建該文件。

http://docs.oracle.com/javase/7/docs/api/java/io/File.html#createNewFile()

File dir = Environment.getExternalStorageDirectory(); 
    if (dir.exists() && dir.isDirectory()) { 
     String exStoragePath = Environment.getExternalStorageDirectory().getAbsolutePath(); 
     File appPath = new File(exStoragePath + "/mbrc/"); 
     appPath.mkdirs(); 
     String tempFilename = "tmp.wav"; 
     String tempDestFile = appPath.getAbsolutePath() + "/" + tempFilename; 

     File newFile = new File(tempDestFile); 
     newFile.createNewFile(); 

     return tempDestFile; 
    } 
+1

你有沒有在清單中添加android.permission.WRITE_EXTERNAL_STORAGE? – dafi

+0

忘記了。謝謝:D – mbrc

相關問題