http://bbs.w3china.org/dispbbs.asp?boardID=2&ID=69946
我初学jena,本体的读取问题一直困扰我。试验出了几种方法,供大家讨论:
OntModel ontModel=ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);第一种方法:ontModel.read("file:E:/java/MeOntology.owl");里面也可以写成相对路径
比如ontModel.read("file:../MeOntology.owl");
第二种方法:try {
File file=new File("E:\\java\\MeOntology.owl");
FileInputStream in=new FileInputStream(file);
ontModel.read(in,null);
}
catch (Exception ex) { }
这里的file同样也可以写成相对路径File file=new File("ontology\\MeOntology.owl"); 这时候的本体存储在程序文件外的一个叫做ontology的文件夹内;
第三种方法: String filePath="E:\\java\\MeOntology.owl";
try {
FileInputStream file = new FileInputStream(filePath);
InputStreamReader in = new InputStreamReader(file, "UTF-8"); ontModel.read(in,"");
in.close();
}
catch (Exception e) {}
这里的filePath同样也可以写成相对路径String filePath="ontology\\MeOntology.owl"; 本体文件存储在程序文件外的一个叫做ontology的文件夹内。
一点愚见,希望大家能够指正!