我从文件Java中读取对象时遇到问题。从文件读取对象
file
是arraylist<projet>
这是保存对象的代码:
try {
FileOutputStream fileOut = new FileOutputStream("les projets.txt", true);
ObjectOutputStream out = new ObjectOutputStream(fileOut);
for (projet a : file) {
out.writeObject(a);
}
out.close();
} catch (Exception e) {
e.printStackTrace();
}
这是阅读的对象从文件::写作正常工作的代码
try {
FileInputStream fileIn = new FileInputStream("les projets.txt");
ObjectInputStream in = new ObjectInputStream(fileIn);
while (in.available() > 0){
projet c = (projet) in.readObject();
b.add(c);
}
choisir = new JList(b.toArray());
in.close();
} catch (Exception e) {
e.printStackTrace();
}
。问题是阅读......它不读任何对象(projet)可能是什么问题?
嗨,你有没有得到你的代码的'e.printStackTrace()'行打印的任何异常消息?如果是这样,请你将跟踪贴到问题上。 – mico
sry我有编辑我的问题cz任何对象重新注册! – user3285843
@mico noo打印任何异常消息 – user3285843