0
파일을 백업 할 위치를 선택할 수있는 백업 프로그램을 만들려고합니다. 파일 위치를 저장하는 데는 문제가 없지만 읽는 것이 문제입니다.파일을 Null로 저장합니다.
저장 방법
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 ("n \"이명 령 +)
prin ts out "null"이지만 "Q'sSavesBackup.cfg"에 저장된 정보를로드해야합니다.
누군가이 문제를 해결할 수있는 방법을 보여 주시겠습니까?
코드가 무엇인지 알지 못하지만이 링크를 사용하여 파일을 올바르게 읽을 수 있습니다. [파일을 올바르게 읽는 법] (http://www.roseindia.net/java/beginners/java-read-file-line-by-line.shtml) – Smit
목적지 문자열에 공백 문자/줄 바꿈 문자가있는 이유는 무엇입니까? 당신이 쓰고있는 파일을 확인 했습니까? – Zhedar