我想保存一個文件中的對象,但該文件沒有出現在設備上,我也沒有得到一個例外。android:不能寫入文件目錄,但可以在包dir
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");
}
}
相反,如果我使用:
try {
fos = new FileOutputStream("/data/data/APP_PACKAGE/settings.ser");
out = new ObjectOutputStream(fos);
它的工作,我可以看到,該文件已經在設備上創建。
但這並不酷,它不是這樣做的,因爲目錄結構將來可能會改變。
我有一個鬼鬼祟祟的懷疑,這是一個權限問題 - 所以它沒有吐出任何logcat或任何錯誤?任何警告? – xil3 2010-07-06 11:01:40
logcat中沒有任何內容。我想過許可問題,並卸載了重新安裝,但仍然沒有。 – Auras 2010-07-06 11:27:43