1
我想在现有文件中附加文本但我无法读取它(我可以读取第一个插入的数据)我不知道什么是错误。 这是写代码(保存文件):在Android中的现有文件中追加数据并读取它
FileOutputStream fos = openFileOutput("test",MODE_APPEND);
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(text);
oos.flush();
oos.close();
,这是如何读取(从文件中读取数据):
FileInputStream fis = openFileInput("test");
ObjectInputStream ois = new ObjectInputStream(fis);
String s=(String) ois.readObject();
while(s != null){
Toast.makeText(getApplicationContext(),s, Toast.LENGTH_SHORT).show();
s=(String) ois.readObject();
Toast.makeText(getApplicationContext(),s, Toast.LENGTH_SHORT).show();
}
恳求帮助我!在写作或阅读代码时是否存在错误