Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
java.lang.IllegalArgumentException:未找到文件_Java_File_Exception_Jena - Fatal编程技术网

java.lang.IllegalArgumentException:未找到文件

java.lang.IllegalArgumentException:未找到文件,java,file,exception,jena,Java,File,Exception,Jena,我正在尝试使用Jena阅读本体论。我在代码中显示的正确目录中有一个Pizza.owl文件,但仍然得到一个错误,即找不到该文件 public static void ReadOntology(){ OntModel onto = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, null); String inputFileName = "C:\\Users\\najib\\studies\\pizza.owl"; try {

我正在尝试使用Jena阅读本体论。我在代码中显示的正确目录中有一个Pizza.owl文件,但仍然得到一个错误,即找不到该文件

public static void ReadOntology(){

OntModel onto = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, null);
String inputFileName = "C:\\Users\\najib\\studies\\pizza.owl";

try {
    Logger logger = Logger.getLogger(Operations.class); 

    PropertyConfigurator.configure("C://Users//najib//Downloads//apache-jena-2.12.0//jena-log4j.properties");
//create the reasoning model using the base
    OntModel model = ModelFactory.createOntologyModel();
// use the FileManager to find the input file
    InputStream in = FileManager.get().open(inputFileName);
    if (in == null) {
        throw new IllegalArgumentException("File: " + inputFileName + " not found");
    }
    model.read(in, "");
//to list classes
    ExtendedIterator<OntClass> classes = model.listClasses();
    while (classes.hasNext()) {
        OntClass cls = (OntClass) classes.next();
        System.out.println("Classes: " + cls.getLocalName());
        for (ExtendedIterator<OntClass> i = cls.listSubClasses(true); i.hasNext();) {
            OntClass c = (OntClass) i.next();
            System.out.print(" " + c.getLocalName() + "\n");
        } // end for
    }
} catch (Exception e) {
    System.out.println(e);
    }
}
publicstaticvoidreadontology(){
OntModel onto=ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM,null);
String inputFileName=“C:\\Users\\najib\\studies\\pizza.owl”;
试一试{
Logger=Logger.getLogger(Operations.class);
configure(“C://Users//najib//Downloads//apache-jena-2.12.0//jena-log4j.properties”);
//使用数据库创建推理模型
OntModel model=ModelFactory.createOntologyModel();
//使用文件管理器查找输入文件
InputStream in=FileManager.get().open(inputFileName);
if(in==null){
抛出新的IllegalArgumentException(“文件:“+inputFileName+”未找到”);
}
型号。以“.”号填列;
//列出课程
ExtendedIterator类=model.listClasses();
while(classes.hasNext()){
OntClass cls=(OntClass)classes.next();
System.out.println(“类:+cls.getLocalName());
for(ExtendedIterator i=cls.ListSubclass(true);i.hasNext();){
OntClass c=(OntClass)i.next();
System.out.print(“+c.getLocalName()+”\n”);
}//结束
}
}捕获(例外e){
系统输出打印ln(e);
}
}
}

我得到以下错误:
java.lang.IllegalArgumentException:File:C:\Users\najib\studies\pizza.owl未找到

当我阅读的
javadoc
时,我发现您必须在文件参数前面加上
“file:”

因此(不测试此答案),我建议尝试以下方法:

String inputFileName = "file:/C:/Users/najib/studies/pizza.owl";

你使用哪种操作系统?java有必要的访问权限吗?@markus我使用Windows 7。我相信Eclipse有权访问
ApacheJena proprieties文件
FileManager的级别是什么?自己的实现?@Naveen,当我这样做时,我得到了
文件:C://Users//najib//studies//pizza.owl未找到
您只需要一个斜杠:
C:/Users/najib/studies/pizza.owl