2010-07-23 82 views

回答

3

下面是如何在一個文件中寫..

FileOutputStream fos = openFileOutput("urls.txt", Context.MODE_PRIVATE); 
fos.write("Alex".getBytes()); 
fos.close(); 

下面是如何讀取該文件:

FileInputStream fis = openFileInput("urls.txt"); 
int c; 
while((c=fis.read())!=-1) 
     { 

      k += (char)c; 
     } 
fis.close(); 

字符串k將包含 「ANKIT」作爲一個字符串。

請注意..文件「urls.txt」在手機內存中形成,您無法在項目中將該文件作爲資源進行訪問。

欲瞭解更多信息,請參閱:http://developer.android.com/guide/topics/data/data-storage.html#filesInternal

+0

我有以下路徑內容的文件://com.android.email.attachmentprovider/1/1/RAW如何讀取這個? – Alex 2010-07-23 10:04:09

+0

openFileInput不起作用 – 2013-06-09 16:12:56

相關問題