0

I would like to create a file in the internal storage and use it to modify the content of an Android app.

My problem is that I would like to keep access to this file in order to edit it at any time.

In spite of all my searchings I didn't find any way to do that.

If any of you could help that would be fantastic !

AstroCB
  • 12,337
  • 20
  • 57
  • 73
Bob Nalyd
  • 21
  • 1
  • 5

1 Answers1

0

This answer was taken from here and it was Shade who found it.

File sdCard = Environment.getExternalStorageDirectory();
File dir = new File (sdcard.getAbsolutePath() + "/dir1/dir2");
dir.mkdirs();
File file = new File(dir, "filename");

FileOutputStream f = new FileOutputStream(file);
...

If you have sensitive data and want to save it to the internal storage you may follow this tutorial.

Community
  • 1
  • 1
Simon Zettervall
  • 1,764
  • 1
  • 15
  • 31
  • Thank you for answering, but my question was about accessing and editing a file located in the Internal storage not the external storage. – Bob Nalyd Mar 08 '13 at 16:26
  • @BobNalyd The internal storage are mostly restricted to the OS and app states et cetera and it is advised to use the external storage. If you check up this link (http://developer.android.com/reference/android/os/Environment.html) it will give you the methods to access the external. However if you have sensitive data then you should use the internal. – Simon Zettervall Mar 08 '13 at 16:36
  • Actually I was not all correct in my previous post, please see my updated answer. – Simon Zettervall Mar 08 '13 at 16:40
  • So from your link @SimonZettervall I should understand that there is **absolutely no way** to access and edit a file in the internal storage after it's been created ? – Bob Nalyd Mar 08 '13 at 17:29
  • @BobNalyd What makes you think that? – Simon Zettervall Mar 11 '13 at 08:36
  • Because the tutorial you provided (and I had checked before) says "By default, files saved to the internal storage are private to your application and other applications cannot access them (nor can the user)" – Bob Nalyd Mar 11 '13 at 14:03
  • @BobNalyd That does not mean YOUR application may not use it. It is private so ONLY your application can use it. Think of it as a private variable in a class. – Simon Zettervall Mar 11 '13 at 15:53