Skip to content

To open file in Java/jena API

Hi I’m currently learning semantic web on java and Jena API. I have an error to open a file which is in the same directory with my class

My code :

public class Tuto7 extends Object {

    static final String inputFileName = "vc-db-1.rdf";

    public static void main(String args[]) throws FileNotFoundException {
        // create an empty model
        Model model = ModelFactory.createDefaultModel();

        // use the FileManager to find the input file
        InputStream in = FileManager.get().open(inputFileName);
        System.out.println( in );
        if ( in == null) {
            throw new IllegalArgumentException("File: " + inputFileName + " not found");
        System.out.println("After open file");
        // read the RDF/XML file in , "");

        // select all the resources with a VCARD.FN property
        ResIterator iter = model.listResourcesWithProperty(VCARD.FN);
        if (iter.hasNext()) {
            System.out.println("The database contains vcards for:");
            while (iter.hasNext()) {
                System.out.println("  " + iter.nextResource()
        } else {
            System.out.println("No vcards were found in the database");

The error : Exception in thread "main" java.lang.IllegalArgumentException: File: vc-db-1.rdf not found

NB : The file is in the same directory


Already resolved by
static final String inputFileName ="/Users/macbook/Documents/IntelliJ/projet2020/webSemantique/src/tp1/vc-db-1.rdf";