2010-07-23 84 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

相关问题