저는 파일을 읽는 데 도움이되는 자바 초보자입니다. 여기에 제가 사용하고있는 코드가 있습니다.Java에서 .txt 파일 읽기 관련 문제
소스 :
public void Escanear()
{
Scanner sc=new Scanner(new File("inicio.txt"));
while(sc.hasNext())
{
String token = sc.next();
if (token.equals("Pared"))
{
int i=sc.nextInt();
int j=sc.nextInt();
_mat=new Pared[i][j];
}
else if(token.equals("Fantasma"))
{
int i=sc.nextInt();
int j=sc.nextInt();
_mat=new Fantasma[i][j];
}
}
}
오류 :
C:\Users\User\Documents\Jorge\Clases UNIMET\Trimestre 5\Estructuras de Datos\Proyecto Pacman\JuegoPacman.java:28: error: unreported exception FileNotFoundException; must be caught or declared to be thrown
Scanner sc=new Scanner(new File("inicio.txt"));
내가 java.io.FileNotFoundException을 가져온, 나는 이미 같은 폴더에있는 .txt 파일을 열었습니다 내가 편집하고있는 수업처럼 ... 어떻게 고칠 수 있을까? 감사.
올바른 경로를 지정하십시오. 'D :/jmd/sample.log'와 같습니다. – Arung
여기에 파일의 전체 경로를 게시하십시오. 국가 기호가 포함되어 있습니까? –