使用Jena响应filenotfoundexception读取本地.owl文件

时间:2013-04-03 08:45:43

标签: rdf jena

我正在进行耶拿的开发。

当我读取本地文件时,即使它只有三行,我也无法正常运行。

这是我的代码:

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.owlfile:\\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

有人能伸出援助之手吗?我完全感到困惑,为什么它不起作用。

1 个答案:

答案 0 :(得分: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();