Galip Galip - 1 year ago 87
Android Question

Saving file to phone instead of SD card

In my app I save an XML file to the user's SD card by doing

File newxmlfile = new File(Environment.getExternalStorageDirectory() + "/Message.xml");

But not all users have SD-cards in their phone and therefore my app is likely to crash.

How must I change my File creating method in order to save the file to the phone's memory instead of the SD-card?

Also, how must I change the loading of the file? (currently:
new InputSource(new FileInputStream(Environment.getExternalStorageDirectory() + "/Message.xml"))

EDIT: I don't think you got the question right. I know the Data-Storage page of the Android Docs and I've read it. I just want to know how I should it adjust it to match my current way of saving and loading a file.

Answer Source

Got it by changing

Environment.getExternalStorageDirectory() + "/Message.xml"


Environment.getDataDirectory() + "/data/com.companyname.appname/files/Message.xml"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download