2016-11-15 10 views
1

Wildflyサーバー上で実行されているSpringでJava8を使用しています。Javaファイルのパスが見つかりません

私は次のパッケージがありますLanguageChunkerServiceImpl

enter image description here

を、私はen-parser-chunking.binのハンドルを取得しようとしていますが、私はエラーを取得:

java.io.FileNotFoundException: en-parser-chunking.bin (The system cannot find the file specified)

マイコード:

LanguageChunkerServiceImpl.java

new FileInputStream("en-parser-chunking.bin"); 

または

new FileInputStream("./src/main/java/com/jobs/spring/service/lang/en-parser-chunking.bin"); 

私はmain方法からこれを実行すると、次はしかし作業を行います。

new FileInputStream("./src/main/java/com/jobs/spring/service/lang/en-parser-chunking.bin"); 

誰でもパスがどうあるべきかアドバイスしていただけますか?あなたは春、リソースのディレクトリにファイルを置くを使用している場合

はあなたに

+0

http://stackoverflow.com/questions/4871051/getting-the-current-working-directory-in-javaルートパスを見つけてそれに移動します。 – Compass

+0

おそらく[クラス#getResourceAsStream](https://docs.oracle.com/javase/7/docs/api/java/lang/Class.html#getResourceAsStream%28java.lang.String%29)を参照してください。 )。 – Mena

+0

[this](http://stackoverflow.com/questions/2914375/getting-file-path-in-java) –

答えて

1

使用している場合は、src/javaにないリソースフォルダにファイルを置く必要があります。

0

following作品をありがとうございました。

 ClassLoader classLoader = getClass().getClassLoader(); 
     File file = new File(classLoader.getResource("en-parser-chunking.bin").getFile()); 
     System.out.println(file.getAbsolutePath()); 
     modelInParse = new FileInputStream(file.getAbsolutePath()); 
関連する問題