[英]To open file in Java/jena API
嗨,我目前正在 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
注意:文件在同一目錄中
已經解決了
static final String inputFileName ="/Users/macbook/Documents/IntelliJ/projet2020/webSemantique/src/tp1/vc-db-1.rdf";
謝謝
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.