开发者

File input output question with Inputstreamreader

I made an android app which writes to a file in an activity. The writing to file, it works like a charm:

FileOutputStream fOut = openFileOutput("myfeeds.txt",
                    MODE_WORLD_READABLE);
         OutputStreamWriter osw = new OutputStreamWriter(fOut);
         osw.write(file);
         osw.flush();
         osw.close();
But when I want to read it back from another acivity it can't find the file...the file exists I checked with DDMS file explorer. Reading file contents:

         FileIn开发者_如何学PythonputStream fis = new FileInputStream("myfeeds.txt");    // cant find file
         InputSource input = new InputSource(fis);
         xr.setContentHandler(this);
         xr.parse(input);

What is the correct location to my file?


Use openFileInput to get FileInputStream object for those files which are written using openFileOutputStream

use the following code

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


You should use

openFileInput( String name )

to read your file.

Regards, STéphane

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜