2013-04-02 59 views
1

我創建一個應用程序,我需要在一個文件中讀取數據,可能進行修改和寫回。目前,我有資產的初始文件,並在精細讀,我剛剛發現然而,你不能寫入到該位置。我想寫入內部存儲。在哪裏寫的android文件

我應該在哪裏寫一個文件,這樣我的應用程序可以在手機上編寫和訪問文件?

我不斷收到不同的實現各種不同的錯誤:以下爲我提供了

filenotfound例外: http://developer.android.com/training/basics/data-storage/files.html

:EROFS唯一的文件系統

public void write(Entry[] newEntries){ 
try { 
    FileOutputStream os = new FileOutputStream(new File("combinationswrite.txt")); 
    OutputStreamWriter osw = new OutputStreamWriter(os); 
    for (int j = 0; j < newEntries.length; j++){ 
     if (newEntries[j] != null){ 
     osw.write(newEntries[j].symbol); 
     osw.write("\t"); 
     for (int i =0; i<6; i++){ 
     osw.write(newEntries[j].getNode(i)); 
     if(i < 5) 
     osw.write(","); 
     else 
     osw.write("\n"); 
     } 
     } 
    } 
    osw.flush(); 
    osw.close(); 
    } catch (IOException e) { 
    e.printStackTrace(); 
    } 
} 

試圖在文檔以下實現的時候讀

openFileOutput方法不被識別

回答

0

從鏈接你是指讓這樣的代碼

public void write(Entry[] newEntries){ 
    try { 
     FileOutputStream os = new FileOutputStream(getTempFile(context , "combinationswrite.txt")); 
     OutputStreamWriter osw = new OutputStreamWriter(os); 
     for (int j = 0; j < newEntries.length; j++){ 
      if (newEntries[j] != null){ 
      osw.write(newEntries[j].symbol); 
      osw.write("\t"); 
      for (int i =0; i<6; i++){ 
      osw.write(newEntries[j].getNode(i)); 
      if(i < 5) 
      osw.write(","); 
      else 
      osw.write("\n"); 
      } 
      } 
     } 
     osw.flush(); 
     osw.close(); 
     } catch (IOException e) { 
     e.printStackTrace(); 
     } 
    } 

public File getTempFile(Context context, String url) { 
    File file; 
    try { 
     String fileName = Uri.parse(url).getLastPathSegment(); 
     file = File.createTempFile(fileName, null, context.getCacheDir()); 
    catch (IOException e) { 
     // Error while creating file 
    } 
    return file; 
} 

這種方法getTempFile將從intarnal存儲

回報您的文件