여기에 비슷한 질문을 게시했습니다 : Read from a file containing integers - java 괜찮은 답변을 얻을 수 없습니다.파일 읽기 오류 (Java)
이제 파일을 읽고 결과를 출력하는이 새로운 코드를 작성했습니다.
파일에서 읽을 때마다 FileNotFoundException이 발생합니다. 코드는 다음과 같습니다 :
import java.io.*;
public class second {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
File f = new File("C:\\Users\\Haroon\\workspace\\ppp\\temperature.txt");
FileReader file = new FileReader(f);
BufferedReader buf = new BufferedReader(file);
String s = null;
while((s = buf.readLine()) != null){
System.out.println(s);
}
}
}
파일이 프로젝트의 폴더에 있기 때문에이 이상하다. 도움이 될 것입니다.
시도한 경우 : "C : /Users/Haroon/workspace/ppp/temperature.txt"를 읽을 수 있습니까? –
"파일이 프로젝트의 폴더에 있기 때문에 이상합니다."- 프로젝트의 폴더는 완전한 파일 이름을 지정한 경우에는 관련이 없습니다. –
슬래시와 동일한 오류가 발생합니다. @JonSkeet 감사합니다. 왜냐하면 처음에는 전체 경로 대신에 temperature.txt 만 쓰고 있었기 때문입니다. – stud91