【问题标题】:To open file in Java/jena API在 Java/jena API 中打开文件
【发布时间】:2020-10-25 23:02:12
【问题描述】:

您好,我目前正在学习有关 java 和 Jena API 的语义网络。 我打开与我的班级位于同一目录中的文件时出错

我的代码:

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
        BasicConfigurator.configure();
        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
        model.read( 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()
                    .getRequiredProperty(VCARD.FN)
                    .getString());
            }
        } else {
            System.out.println("No vcards were found in the database");
        }
    }
}

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

注意:文件在同一目录中

【问题讨论】:

    标签: java sparql rdf jena semantic-web


    【解决方案1】:

    已经解决
    static final String inputFileName ="/Users/macbook/Documents/IntelliJ/projet2020/webSemantique/src/tp1/vc-db-1.rdf";

    谢谢

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-25
      相关资源
      最近更新 更多