我正在尝试制作一个备份程序,允许您选择要备份文件的位置。我可以保存文件位置,但读取它是问题所在。
保存方法
public static void write(String importdest) throws IOException {
// Create some data to write.
String dest = importdest;
// Set up the FileWriter with our file name.
FileWriter saveFile = new FileWriter("Q'sSavesConfig.cfg");
// Write the data to the file.
saveFile.write(dest);
// All done, close the FileWriter.
saveFile.close();
}
可变加载方法
public static String read() throws IOException {
String dest;
BufferedReader saveFile = new BufferedReader(new FileReader("Q'sSavesConfig.cfg"));
// Throw away the blank line at the top.
saveFile.readLine();
// Get the integer value from the String.
dest = saveFile.readLine();
// Not needed, but read blank line at the bottom.
saveFile.readLine();
saveFile.close();
// Print out the values.
System.out.println(dest + "\n");
System.out.println();
return dest;
}
我的主要问题是
System.out.println(dest + "\n")
打印出“null”,但它应该加载“Q'sSavesBackup.cfg”中保存的信息
有人可以告诉我如何解决这个问题吗?