我從文件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