-4
爲什麼代碼無法實現!不能讀取serlaizable文件! 它正確地寫在文件中,但不能讀取爲什麼代碼無法實現!無法讀取serlaizable文件?
public ArrayList<customer> read_file(){
ArrayList <customer>file = new ArrayList<customer>();
try {
File f= new File("file.bin");
ObjectInputStream is= new ObjectInputStream (new FileInputStream("file.bin"));
int x=(int) f.length();
while(is.available()!=0){
file.add((customer)is.readObject()) ;
}
} catch (FileNotFoundException ex) {
Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException | ClassNotFoundException ex) {
Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
}
return file ;}
此處粘貼代碼。不要給一些外部鏈接。 –
請參見[什麼是堆棧跟蹤,以及如何使用它來調試我的應用程序錯誤?](http://stackoverflow.com/q/3988788/418556)&[什麼是空指針異常,以及如何修復它?](http://stackoverflow.com/q/218384/418556) –
我建議,不要使用序列化,而是使用像JAXB或其他方法,序列化僅用於短期存儲對象,通常用於傳輸線...它有問題,很容易破壞 – MadProgrammer