I have an Android app where I need to save a file.
I create the file like this:
FileOutputStream fOut = openFileOutput(fileName,
MODE_WORLD_READABLE);
osw = new OutputStreamWriter(fOut);
I open it like this:
FileInputStream srcFileStream = openFileInput(fileName);
This works fine with internal memory files.
I’ve added a prefrences to my app, where the user can select to save the file to the sd card instead.
I try this command:
if (Prefs.getCard(this))
fileName="/sdcard/"+fileName;
Meaning that if the Prefrences is yes, I add “/sdcard/” infront of the file name.
The rest of the code remains the same,
This does not seem to work, as I get an Exception:
File /sd/file1 contains a path seperator
How can I use the same code for both saving to SD card and to internal memory, with just a small modification as i tried above?
This should work..