I'm trying to save an object in a file but the file doesn't appear on the device and I don't get an exception either.
public static void save(Context ctx) {
Log.i("App serialization", "Saving to settings.ser: " + ctx.getFileStreamPath("settings.ser"));
FileOutputStream fos = null;
ObjectOutputStream out = null;
try {
fos = ctx.openFileOutput("settings.ser", Context.MODE_PRIVATE);
out = new ObjectOutputStream(fos);
out.writeObject(ApplicationData.settings);
out.flush();
out.close();
//fos.close();
Log.i("App serialization", "Finished writing to settings.ser");
}
catch(IOException ex) {
ex.printStackTrace();
Log.e("App serialization", "Could not save to settings.ser");
}
}
If instead I use:
try {
fos = new FileOutputStream("/data/data/APP_PACKAGE/settings.ser");
out = new ObjectOutputStream(fos);
It works and I can see that the file has been created on the device.
But this isn't cool and it's not the way to do it because the directory structure may change in the future.