java - Jena 库未将输出写入外部 RDF/XML 文件

标签 java file-io jena

我的 jena 库的写入方法有问题。 我有以下一段代码,应该将输出写入外部文件,但它没有这样做。

import com.hp.hpl.jena.rdf.model.*;
import com.hp.hpl.jena.vocabulary.*;
import com.hp.hpl.jena.rdf.model.impl.ModelCom;


public class Tutorial04 extends Object {

// some definitions
static String tutorialURI  = "http://hostname/rdf/tutorial/";
static String briansName   = "Brian McBride";
static String briansEmail1 = "brian_mcbride@hp.com";
static String briansEmail2 = "brian_mcbride@hpl.hp.com";
static String title        = "An Introduction to RDF and the Jena API";
static String date         = "23/01/2001";

@SuppressWarnings("unused")
public static void main (String args[]) {

    // some definitions
    String personURI    = "http://somewhere/JohnSmith";
    String givenName    = "John";
    String familyName   = "Smith";
    String fullName     = givenName + " " + familyName;
    // create an empty model
    Model model = ModelFactory.createDefaultModel();

    // create the resource
    //   and add the properties cascading style
    Resource johnSmith
      = model.createResource(personURI)
             .addProperty(VCARD.FN, fullName)
             .addProperty(VCARD.N,
                          model.createResource()
                               .addProperty(VCARD.Given, givenName)
                               .addProperty(VCARD.Family, familyName));

    // now write the model in XML form to a file
  //  model.write(System.out, "RDF/XML");
    model.write(System.out,"RDF/XML");
}

}

最佳答案

你有:

model.write(System.out,"RDF/XML");

其中表示“请将此模型的内容写入标准输出”,即不要写入任何命名文件。要将模型写入文件,您需要说出哪个文件:

String fileName = "your_file_name_here.rdf";
FileWriter out = new FileWriter( fileName );
try {
    model.write( out, "RDF/XML-ABBREV" );
}
finally {
   try {
       out.close();
   }
   catch (IOException closeException) {
       // ignore
   }
}

关于java - Jena 库未将输出写入外部 RDF/XML 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16766408/

相关文章:

JAVA - 如何从 JTree 访问 ArrayList 的对象

java - 在 Java 中右键单击 JTextArea 时显示 JPopupMenu?

php - Codeigniter 多个文件上传困惑文件扩展名

python - 读取具有指定换行符的文件

java - 如何使用 Jena API、Fuseki 和 TDB 基于现有 OWL 文件创建 Jena Triple Store?

java - 如何拦截自己创建的JdbcTemplate实例

java - 不使用 Float.MAX_VALUE 查找 float 的最大值?

java - 尝试通过JSP查询RDF模型时发生错误?

javascript - 无法构造 'Blob' : The 1st argument provided is either null, 或无效的 Array 对象。

java - 通过 Java 代码插入一些数据时,Sparql 查询不会更新