我正在尝试为库应用程序实现保存和加载功能,该应用程序存储技术手册。
理想情况下,我希望应用程序将库中的手册保存为文本文件,然后在用户需要时将它们加载回库中。
目前我有这段代码来保存和加载文本文件:
//Choice 7: Load Library:
if(Menu.menuChoice == 7){
boolean loadYesNo = Console.readYesNo("\n\nThe manualKeeper app is able to load and display any 'Library.txt' files \nfound in your home folder directory.\n\nWould you like to load and display library? (Y/N):\n");
String fileName = "Library.txt";
String line;
if(loadYesNo){
try {
BufferedReader input = new BufferedReader (new FileReader (fileName));
if (!input.ready()) {
throw new IOException();
}
while ((line = input.readLine()) != null) {
Library.ManualList.add(line);
}
input.close();
} catch (IOException e) {
System.out.println(e);
}
Menu.displayMenu();
} else if(!loadYesNo){
System.out.println("\n\n--------------------------------------------------------------------------");
System.out.println("\n Library not loaded!\n");
System.out.println("--------------------------------------------------------------------------\n");
Menu.displayMenu();
}
}
//Choice 0: Exit the program:
if(Menu.menuChoice == 0){
if(Menu.menuChoice == 0){
if(Library.ManualList.size() > 0){
boolean saveYesNo = Console.readYesNo("\nThe manualKeeper app is able to save your current library to a '.txt' \nfile in your home folder directory (C:\\Users\\ 'YOUR NAME').\n\nWould you like to save the current library? (Y/N):\n");
File fileName = new File ("Library.txt");
if(saveYesNo==true){
try {
FileWriter fw = new FileWriter(fileName);
Writer output = new BufferedWriter(fw);
for (int i = 0; i < Library.ManualList.size(); i++){
output.write(Library.ManualList.get(i).displayManual() + "\n");
}
output.close();
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "I cannot create that file!");
}
}
else if(saveYesNo==false){
System.out.println("\n\n--------------------------------------------------------------------------");
System.out.println("\n Library not saved!\n");
System.out.println("--------------------------------------------------------------------------\n");
break exit;
}
Menu.displayMenu();
}else if(Library.ManualList.isEmpty()){
Menu.displayMenu();
}
}
}
}
System.out.println("\n ~ You have exited the manualKeeper app! ~ ");
System.out.println("\n Developed by Oscar - 2014 - UWL\n");
System.out.println("\n <3\n");
}
}
尝试运行时遇到以下错误:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
ManualList cannot be resolved
at library.Manual.run(Manual.java:139)
at library.startLibrary.main(startLibrary.java:11)