tags:

views:

116

answers:

1

Hello Guys,

I am saving details in out.txt file which has created a text file in data/data/new.android/files/out.txt. I am able to append information to the text, however, I am unable to read this file. I used the following procedures to read the file :

File file = new File( activity.getDir("data", Context.MODE_WORLD_READABLE), "new/android/out.txt");
 BufferedReader br = new BufferedReader(new FileReader(file));

Can anyone please help me out to fix this issue ?

Regards, Sunny.

A: 

You can read a line at a time with this:

FileInputStream fis;
final StringBuffer storedString = new StringBuffer();

try {
    fis = openFileInput("out.txt");
    DataInputStream dataIO = new DataInputStream(fis);
    String strLine = null;

    if ((strLine = dataIO.readLine()) != null) {
        storedString.append(strLine);
    }

    dataIO.close();
    fis.close();
}
catch  (Exception e) {  
}

Change the if to while to read it all.

hermy