텍스트 파일을 읽는 프로그램을 얻으 려하지만 프로젝트 디렉토리에 potato.txt 파일이 설정되어 있어도 FileNotFoundException이 발생합니다.스캐너로 Java에서 파일 읽기
import java.io.File;
import java.util.Scanner;
public static void main(String[] args) {
String potato = "potato.txt"; // assume this line can't be changed at all
Scanner scan = new Scanner(new File(potato)); // throws FileNotFoundException
while (scan.hasNextLine()) {
String line = scan.nextLine();
System.out.println(line);
}
}
}
당신의 파일은 정확히 무엇입니까? – Carlton
절대 경로를 사용해보십시오. – mdp
프로젝트 구조 게시하시기 바랍니다 – Saravana