2012-02-19 20 views
1

如何在Android項目文件夾格式目錄jvm無法看到datass.txt或有時logcat說只讀文件...(我把datass.txt在主項目根)節省一個字符串數組到一個文件中的錯誤

我傳遞一個字符串數組,並希望將其保存到一個文件datass.txt所以沒有連接互聯網時,我可以檢索數據

public void FileWrite(String[] temp) throws IOException{ 
     File m = new File("datass.txt"); 
    final String[] descs = temp ; 
    DataOutputStream out = new DataOutputStream(new 
       BufferedOutputStream(
        new FileOutputStream(m))); 


    for (int i = 0; i < 31; i ++) { 

      out.writeUTF(descs[i]); 

     } 
} 
+2

你的文件在哪裏?如果您嘗試訪問外部文件,則可能需要添加權限。 – kosa 2012-02-19 20:34:59

回答

0

看來你可能一個索引出界異常的我是不知道,但要保護你自己改變for循環頭到這

for(int i =0; i < descs.length ; ++i) 
1

您需要在AndroidManiFest.xml文件中添加文件寫入權限。

android.permission.WRITE_EXTERNAL_STORAGE 

請訪問此link各種其他權限集。

相關問題