"RandomAccessFile"을 사용하여 문자열을 쓰고 싶지만 "fio.writeBytes (file1str)"은 끝에 약간의 쓰레기를 추가합니다 문자열의 :RandomAccessFile.writeBytes()로 작성된 파일에 예기치 않은 여분의 문자가 있습니다.
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
try {
System.out.println("Enter the D of planets: ");
file1str = in.readLine();
fio = new RandomAccessFile(new File("file1"), "rw");
fio.writeBytes(file1str);
System.out.println("Your enter: ");
for (String retval: file1str.split(",")) {
System.out.println(retval);
}
fio.close();
System.out.println("Data saves to 'file1'!");
}
catch(FileNotFoundException e){
System.out.println("File not found");
}
catch(IOException e){
System.out.println("Error1");
}
}
.... 그러나 우리는 파일 열려있는 경우, 우리는 말에 10,700 추가 참조 :
내 나쁜 영어에 대한죄송합니다
코드가 잘 보이고, 내 환경에서 작동합니다. in.close(); 읽기 코드 –
위의 코드 스 니펫은 예상대로 작동해야합니다. 이 코드 이후에 파일에 아무 것도 쓰지 않으셨습니까? 여기에 전체 수업을 게시 할 수 있습니까? – Fayaz