1

i am new in android. i want to make a program that in it i will write some text to some files and read them another time.

i am confused abut how i can do it.

i use at first from below code for reading:

InputStreamReader in = new InputStreamReader(ctx.openFileInput("syncConfig.ini"));

it not works on LG devices between Samsung, LG and Sony that i am testing on them.

i think that at some other devices may be not works.

then i use below code :

String sdcard = Environment.getExternalStorageDirectory().getPath();
FileInputStream in = new FileInputStream(new File(sdcard+"/yekana_data/syncConfig.ini"));

the directory yekana_data are exists.

then i think that some devices may have no sdcard or not mounted or device is connected to PC or so on, at this time my program not works or will be wrong later.

i want to write to a place that all devices support it and in all times is accessible for my program.

how i can solve it?

Yekta Mghani
  • 57
  • 1
  • 6
  • Check [this link](http://stackoverflow.com/questions/5527764/get-application-directory) – Merlevede Mar 07 '14 at 21:01
  • Context.openFileOutput() works on all properly functioning Android devices, for a valid Context. openFileInput() will work if the file has previously been created (since the last time the app was installed or its data manually cleared) by some means such as the former. – Chris Stratton Mar 07 '14 at 21:03
  • For android, getExternalStorage() does not necessarily refer to an SD card. If the device does not have an SD card (for example, my HTC one), it will write to the phone's internal disk (in a different location from openFileInput() ). So it should work on basically all devices. – Gak2 Mar 07 '14 at 21:06
  • I can solve my LG problem but i don't understand file system on android i found it at [this](http://developer.android.com/training/basics/data-storage/files.html) address. and perfect storage for me is internal storage. – Yekta Mghani Mar 07 '14 at 21:16

1 Answers1

1

You can learn more about saving files on the android developer site.

http://developer.android.com/training/basics/data-storage/files.html

Alex
  • 3,382
  • 2
  • 32
  • 41
  • 1
    yes i found : Internal storage: 1-It's always available. 2-Files saved here are accessible by only your app by default. 3-When the user uninstalls your app, the system removes all your app's files from internal storage. – Yekta Mghani Mar 07 '14 at 21:09