I have the following code in a static class called Methods that is archived in a jar:
System.out.println(Methods.class.getResource("tagdict.txt")); // 1
URL test = Methods.class.getResource("tagdict.txt"); // 2
System.out.println(test.getPath()); // 3
TagDictionary dict = new POSDictionary(test.getPath()); // 4
The first System.out
(1) says:
rsrc:de/fhg/scai/bio/harsha/classificationworkflow/tagdict.txt
The second System.out
(2) says:
de/fhg/scai/bio/harsha/classificationworkflow/tagdict.txt
Line 4 throws a
java.io.FileNotFoundException: de/fhg/scai/bio/harsha/classificationworkflow/tagdict.txt (No such file or directory)
The file tagdict.txt
is placed in the same package as the Method.class
, which is de/fhg/scai/bio/harsha/classificationworkflow
.
I do not understand why line 4 throws a FileNotFoundException
even though the file was found already inside the jar.