【问题标题】:java.lang.IllegalArgumentException: File Not foundjava.lang.IllegalArgumentException:找不到文件
【发布时间】:2014-08-04 11:40:31
【问题描述】:

我正在尝试使用 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);
    }
}

}

我收到以下错误:java.lang.IllegalArgumentException: File: C:\Users\najib\studies\pizza.owl not found

【问题讨论】:

  • 您使用哪种操作系统? java是否有必要的访问权限?
  • @markus 我使用的是 Windows 7。我相信 Eclipse 有权限,因为它可以访问apache jena proprieties file
  • FileManager 的类是什么?自己实现?
  • @Naveen,当我这样做时,我得到了File: C://Users//najib//studies//pizza.owl not found
  • 你只需要一个斜杠:C:/Users/najib/studies/pizza.owl

标签: java file exception jena


【解决方案1】:

当我阅读FileManagerjavadoc 时,我看到您必须在文件参数前加上"file:"

所以(不测试这个答案)我建议尝试一下:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-08
    • 1970-01-01
    • 2015-02-02
    • 2020-10-27
    • 2020-11-26
    • 2013-06-04
    • 2013-05-31
    相关资源
    最近更新 更多