我在一個靜態類調用的方法下面的代碼是在一個罐子裏存檔: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。
我不明白爲什麼第4行拋出FileNotFoundException,即使該文件已被發現在jar中。
這將有助於POSDictionary構造函數的代碼,因爲引發異常。 – Viruzzo 2012-01-17 09:47:48