Une autre approche pour le même problème peut vous aider à lire et à écrire un fichier dans un contexte privé d'application
String NOTE = "note.txt";
private void writeToFile() {
try {
OutputStreamWriter out = new OutputStreamWriter(openFileOutput(
NOTES, 0));
out.write("testing");
out.close();
}
catch (Throwable t) {
Toast.makeText(this, "Exception: " + t.toString(), 2000).show();
}
}
private void ReadFromFile()
{
try {
InputStream in = openFileInput(NOTES);
if (in != null) {
InputStreamReader tmp = new InputStreamReader(in);
BufferedReader reader = new BufferedReader(tmp);
String str;
StringBuffer buf = new StringBuffer();
while ((str = reader.readLine()) != null) {
buf.append(str + "\n");
}
in.close();
String temp = "Not Working";
temp = buf.toString();
Toast.makeText(this, temp, Toast.LENGTH_SHORT).show();
}
} catch (java.io.FileNotFoundException e) {
// that's OK, we probably haven't created it yet
} catch (Throwable t) {
Toast.makeText(this, "Exception: " + t.toString(), 2000).show();
}
}