【问题标题】:Jena library is not writing output to an external RDF/XML fileJena 库未将输出写入外部 RDF/XML 文件
【发布时间】:2013-05-27 04:41:58
【问题描述】:

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

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

}

【问题讨论】:

    标签: java file-io jena


    【解决方案1】:

    你有:

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

    【讨论】:

    • 谢谢伊恩 :) 它有帮助。在我最后一年的项目中,我还需要你的更多帮助。您是否也了解耶拿图书馆?
    • 很高兴它有帮助。如果您在 Jena 上需要其他帮助,可以继续在这里提问或向 Jenu 用户群发消息:见jena.apache.org/help_and_support/index.html
    • 嗨伊恩。请问可以给我你的邮箱吗?本周我将在耶拿的一些任务上需要帮助
    • 您好 Faisal,通过电子邮件发送耶拿问题的最佳地点是我在上一条评论中提到的耶拿用户列表。你会得到一整个社区的人来帮助你,而不仅仅是一个人。此外,您的问题和他们得到的答案可能对其他人有所帮助。
    猜你喜欢
    • 1970-01-01
    • 2011-09-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-03
    • 1970-01-01
    • 1970-01-01
    • 2013-03-20
    相关资源
    最近更新 更多