-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