Friday, 27 September 2013

Android - Save to a text file

Android - Save to a text file

I am trying to write text to a file but i cant seem to get it to work.
public static void saveState(){
String data = age + "," ;
FileOutputStream fos;
Context con = getApplicationContext();
try {
fos = con.openFileOutput("state", 0);
OutputStreamWriter outputStreamWriter = new
OutputStreamWriter(fos);
outputStreamWriter.write(data);
outputStreamWriter.close();
}
catch (IOException e) {
Log.e("Exception", "File write failed: " + e.toString());
}
}
I have looked around and it seems i cant call openFileOutput() with out
the context but have no idea "Context con = getApplicationContext()" will
not work. it just tells me that getapplicationcontext is undefined for the
type. Can anyone help me out here?

No comments:

Post a Comment