2013-04-03 44 views
0

我正在做耶拿開發。使用Jena響應filenotfoundexception讀取本地.owl文件

當我讀取本地文件時,即使它只有三行,我也無法正常工作。

這裏是我的代碼:

OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM); 
model.read(owlPath, null); 
Iterator<OntClass> it = model.listClasses(); 

while (it.hasNext()) { 
    OntClass ontclass = it.next(); 
    System.out.println(ontclass.getLabel(null)); 
} 

owlpath值是像file:\\animals-rdf.owl,或file:\\D:\\Eclipse\\workspace\\jena_demo\\sources\\amimal-rdf.owl,或者沒有file:\\前綴,甚至當我用命名空間example.com# + filepath,它仍然會通過。

具體錯誤報告是:

Exception in thread "main" com.hp.hpl.jena.shared.WrappedIOException:  
java.io.FileNotFoundException: \animals-rdf.owl 

可能有人舉個手?我完全困惑,爲什麼它不能工作。

回答

4

您的文件URI已損壞。嘗試:

file:///D:/Eclipse/workspace/jena_demo/sources/animal-rdf.owl 

AIUI這就是它應該如何在Windows上工作。你也可以使用一個文件輸入流,這將避免需要構建一個文件URI:

InputStream in = new FileInputStream("animal-rdf.owl"); // or any windows path 
model.read(in, null); 
in.close(); 
相關問題