Android 序列化问题
我在序列化对象时遇到了一些问题 我想我遗漏了一些东西,因为我的应用程序没有像应该的那样保存.dat 让我们展示一些代码: 加载.dat文件Android 序列化问题,android,serialization,Android,Serialization,我在序列化对象时遇到了一些问题 我想我遗漏了一些东西,因为我的应用程序没有像应该的那样保存.dat 让我们展示一些代码: 加载.dat文件 public void gravar(ObjectOutputStream out) throws IOException { out.writeObject(lista); out.writeObject(cadeiras); out.writeObject(notas); out.close(); }
public void gravar(ObjectOutputStream out) throws IOException {
out.writeObject(lista);
out.writeObject(cadeiras);
out.writeObject(notas);
out.close();
}
public void carregar(ObjectInputStream in) throws IOException, ClassNotFoundException {
lista=(ArrayList<String>) in.readObject();
cadeiras=(ArrayList<String>) in.readObject();
notas= (ArrayList<String>) in.readObject();
in.close();
}
保存.dat文件
public void gravar(ObjectOutputStream out) throws IOException {
out.writeObject(lista);
out.writeObject(cadeiras);
out.writeObject(notas);
out.close();
}
public void carregar(ObjectInputStream in) throws IOException, ClassNotFoundException {
lista=(ArrayList<String>) in.readObject();
cadeiras=(ArrayList<String>) in.readObject();
notas= (ArrayList<String>) in.readObject();
in.close();
}
fich这是:
private static String fich = "gravar.dat";
我错过了什么?为了获得更好的帮助,我将代码放在这里
提前谢谢 您应该将整个路径而不仅仅是文件名传递给
FileOutputStream
如果那样做不起作用,试试看
new FileOutputStream(new File(fich));
解决方法是,而不是
out = new ObjectOutputStream(new FileOutputStream(fich));
粘贴这个
out = new ObjectOutputStream(this.openFileOutput(fich, Context.CONTEXT_IGNORE_SECURITY));
输出也一样。我知道答案,我会在可能的时候(+/-7小时)发布答案。