나는 포함하고 싶은 텍스트 파일로서 resources 폴더에 Jar 파일입니다. 여기에는 최소한의 예:
import java.io.File;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Main main = new Main();
main.readFile( "test.txt" );
}
public void readFile(String fileName){
File file = new File( getClass().getResource( fileName ).getPath() );
try{
Scanner scanner = new Scanner( file );
while ( scanner.hasNextLine() ){
System.out.println( scanner.nextLine() );
}
}catch (Exception e){
System.out.println( e );
}
}
}
여기에는 무엇이 test.txt 파일:
hello
world
이것은 어떻게 프로젝트처럼 보인:
나는 할 수 있는 코드를 실행합니다. 방법은 내가 생성되 항아리는 다음과 같습니다:
나는 이미 추가 resources 폴더를 클릭하여"+"기호입니다. 그러나 제가 생성된 Jar 파일,그것은 여전히 불평 FileNotFoundException.
어떤 방법이 있나요?