我目前正在寫的方法:從內存寫於Android內存/讀任何對象/
- 讀取對象
- 寫入對象存儲
我想救一個字符串對象,並再次閱讀,但我的代碼不起作用。
這是我的代碼:
public void writeObjectToMemory(String filename, Object object) {
FileOutputStream fos;
try {
fos = game.openFileOutput(filename, Context.MODE_PRIVATE);
ObjectOutputStream os = new ObjectOutputStream(fos);
os.writeObject(object);
os.close();
}
catch (FileNotFoundException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
}
public void readObjectFromMemory(String filename, Object object) {
FileInputStream fis;
try {
fis = game.openFileInput(filename);
ObjectInputStream is = new ObjectInputStream(fis);
object = is.readObject();
is.close();
}
catch (FileNotFoundException e) {
e.printStackTrace();
}
catch (StreamCorruptedException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
問題是什麼,哪部分沒有工作?任何堆棧跟蹤? – Caner