【发布时间】:2013-01-11 00:46:23
【问题描述】:
我正在尝试制作一个备份程序,让您可以选择备份文件的位置。我可以保存文件位置,但读取它是个问题。
保存方法
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”中的信息
有人可以告诉我如何解决这个问题吗?
【问题讨论】:
-
我不知道您的代码是什么,但是您可以使用此链接正确读取文件。 How to read file properly
-
为什么你的目标字符串中有空格/换行符?你检查你正在写的文件了吗?
标签: java null load save loading