텍스트 파일을 읽는 프로그램을 작성 중입니다. 읽은 값을 인쇄 할 때 값이 잘못 표시됩니다. 다음과 같이텍스트 파일을 읽을 때 잘못된 텍스트가 표시됩니다.
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class SearchFile {
public static void main(String[] args) {
BufferedReader br = null;
try {
String sCurrentLine;
br = new BufferedReader(new FileReader("C:\\test.txt"));
while ((sCurrentLine = br.readLine()) != null) {
System.out.println(sCurrentLine);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (br != null)br.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
}
출력은 다음과 같습니다 : 텍스트 파일은 다음과 같이 텍스트 파일은 읽기 다음 데이터
This is line one
This is line two
This is line three
This is line four
코드가 포함되어
이 문제를 해결하는 데 도움이 바랍니다. 출력을 가비지 문자로 표시하는 이유는 무엇입니까?
값에 몇 가지 추가 인코딩이있는 것 같습니다. 파일을 어떻게 만들었습니까? 어떻게 표시합니까 (터미널 창을 통해 IDE 콘솔 ???) – MadProgrammer
파일의 인코딩은 무엇입니까? –
그것은 나를 위해 잘 작동하고 있습니다. 나는 인코딩 문제라고 생각합니다. – PSR