2011-06-22 96 views
0

我做了一个android应用程序,它将一个文件写入到一个activity中。 写入文件,它的工作原理就像是一个魅力: Inputstreamreader文件输入输出问题

FileOutputStream fOut = openFileOutput("myfeeds.txt", 
        MODE_WORLD_READABLE); 
     OutputStreamWriter osw = new OutputStreamWriter(fOut); 
     osw.write(file); 
     osw.flush(); 
     osw.close();
但是,当我想从另一个活性中读取它时,它无法找到该文件...该文件存在我使用DDMS文件浏览器进行了检查。 读取文件内容:

 
     FileInputStream fis = new FileInputStream("myfeeds.txt"); // cant find file 
     InputSource input = new InputSource(fis); 
     xr.setContentHandler(this); 
     xr.parse(input); 

什么是正确的位置,我的档案?

+0

你有没有查了一下Android文档[内部和外部文件存储装置(http://developer.android.com/guide/topics/data/data-storage.html#filesInternal) ? – Flo

+0

你应该接受一个答案。 – Snicolas

回答

1

使用openFileInput获得的FileInputStream对象,其使用openFileOutputStream

使用下面的代码

FileInputStream fiss = openFileInput("myfeeds.txt"); 
InputSource input = new InputSource(fis); 
     xr.setContentHandler(this); 
     xr.parse(input); 
+0

感谢您的快速响应... openFileInput无法识别,所以使用上面的代码,我解决了它... –

0

写这些文件,您应该使用

openFileInput(String name) 

阅读您的文件。

问候, 斯特凡