Jena库未将输出写入外部RDF/XML文件 [英] Jena library is not writing output to an external RDF/XML file

查看:69
本文介绍了Jena库未将输出写入外部RDF/XML文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的耶拿图书馆的写作方法有问题. 我有以下一段代码应该将输出写入外部文件中,但没有这样做.

I am having an issue with my jena library's writing method. I have following piece of code which is supposed to write the output in external file but it is not doing so.

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

表示请将该模型的内容写入标准输出" ,即不要写入任何命名文件.要将模型写入文件,您需要说出哪个文件:

which says "please write the contents of this model to standard output" i.e. not to any named file. To write the model to a file, you'll need to say which file:

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

这篇关于Jena库未将输出写入外部RDF/XML文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆