当我在类中执行方法时,我的应用程序崩溃了。请告诉我什么是错误或优化这个课程的方法。它运行时不会创建任何错误消息。所以我不知道什么是错的。我已经尝试了所有我知道的并且能够找到其他工作的评论。
package main;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Scanner;
public class List {
public static void saveList(ArrayList<String> x){
Date date = Calendar.getInstance().getTime();
DateFormat ft= new SimpleDateFormat("W-MM-yyyy");
String fileName= ft.format(date)+ ".bin";
ObjectOutputStream os;
try {
os = new ObjectOutputStream(new FileOutputStream(fileName));
os.writeObject(loadList().addAll(x));
os.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public static ArrayList<String> loadList() throws IOException{
Date date = Calendar.getInstance().getTime();
DateFormat ft= new SimpleDateFormat("W-MM-yyyy");
String fileName= ft.format(date)+ ".bin";
ArrayList<String> array= new ArrayList<>();
ObjectOutputStream on;
on = new ObjectOutputStream(new FileOutputStream("Names.bin"));
on.writeUTF(fileName);
on.close();
ObjectInputStream or;
try {
or = new ObjectInputStream(new FileInputStream("Names.bin"));
String hi= new String(or.readUTF());
or.close();
or= new ObjectInputStream(new FileInputStream(hi));
Scanner reader= new Scanner(System.in);
int in= reader.nextInt();
while(in!= 0){
array.add(Integer.toString(in));
in= reader.nextInt();
}
reader.close();
or.close();
} catch (FileNotFoundException e) {
System.out.println("File Not Found");
}
return array;
}
}
&#13;