私はjarファイルにアーカイブされたメソッドと呼ばれる静的クラスに次のコードを持っている:FileNotFoundException。動作し、同時に動作しませんか?
1 System.out.println(Methods.class.getResource("tagdict.txt"));
2 URL test=Methods.class.getResource("tagdict.txt");
3 System.out.println(test.getPath());
4 TagDictionary dict = new POSDictionary(test.getPath());
最初のSystem.out(1)言葉:
rsrc:de/fhg/scai/bio/harsha/classificationworkflow/tagdict.txt
第二のSystem.outを( 2)言葉:
de/fhg/scai/bio/harsha/classificationworkflow/tagdict.txt
4行目は
java.io.FileNotFoundException: de/fhg/scai/bio/harsha/classificationworkflow/tagdict.txt (No such file or directory)
をスローします
ファイル 'tagdict.txt'は、 'Method.class'と同じパッケージ(de/fhg/scai/bio/harsha/classificationworkflow)に配置されています。
私は、ファイルがまだjarファイル内に見つかっていても、4行目がFileNotFoundExceptionをスローする理由を理解していません。
'POSDictionary'のコンストラクタのコードは、そこに例外がスローされるので役立ちます。 – Viruzzo