-2

I am trying to read an Ontology using Jena. I have a file Pizza.owl in the correct directory shown in the code, but I still get an error that the file is not found.

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);
    }
}

}

I get the following error: java.lang.IllegalArgumentException: File: C:\Users\najib\studies\pizza.owl not found

14
  • Which OS do you use? Does java have the necessary access rights?
    – Markus
    Aug 4, 2014 at 11:42
  • @markus I use Windows 7. I believe that Eclipse has the rights since it can access the apache jena proprieties file
    – callback
    Aug 4, 2014 at 11:43
  • What's the class of FileManager? Own implementation?
    – Markus
    Aug 4, 2014 at 11:44
  • @Naveen, when I did, I got File: C://Users//najib//studies//pizza.owl not found
    – callback
    Aug 4, 2014 at 11:44
  • You only need a single slash: C:/Users/najib/studies/pizza.owl
    – Markus
    Aug 4, 2014 at 11:45

1 Answer 1

0

When I read the javadoc of FileManager, I see you have to prefix your file parameter with "file:"

So (without testing this answer) I suggest to try it with:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.