-3

How can I create a file(using Java for Android) in my Application data directory and write an integer in it and then use that integer? I think I would save it in .txt or .xml file.

user3578286
  • 147
  • 4
  • 10

2 Answers2

0

If you would like to save the file to 'internal' memory (making the file only accessible to the app), then do the following:

 OutputStreamWriter outputWriter = new OutputStreamWriter(openFileOutput("somefile.xml", Context.MODE_PRIVATE));
 String fileContent = "<xml>xmlstuff</xml>";
 outputWriter.write(fileContent);
 outputWriter.close();
bkane521
  • 386
  • 2
  • 10
0

You can use the methods openFileOutput, and openFileInput from the context, you should have access to this methods through your Activity.

You can check it on bellow link http://developer.android.com/reference/android/content/Context.html#openFileInput(java.lang.String)