0
我試圖製作一個備份程序,允許您選擇要備份文件的位置。我很好,保存文件的位置,但讀它是問題。讀取保存文件爲空
節省方法
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」 個)
prin但它應該加載保存在「Q'sSBackupBackup.cfg」中的信息。
有人請告訴我如何解決這個問題嗎?
我不知道你的代碼是什麼,但你可以使用這個鏈接正確地讀取文件。 [如何正確讀取文件](http://www.roseindia.net/java/beginners/java-read-file-line-by-line.shtml) – Smit
爲什麼你的目標字符串中有空格/換行符?你檢查了你正在寫的文件嗎? – Zhedar