为什么代码无法消除!无法读取可格化的文件! 它在文件中正确写入但无法读取
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 ;}
答案 0 :(得分:0)
您的错误是空指针异常。您将客户数组初始化为null。我建议改用ArrayList。