使用操作数据保护插件

时间:2017-12-17 10:37:50

标签: java protege

我正在尝试为protege创建一个插件,它将操纵它的一些日期并对它们做一些事情,但当我尝试在文件中写入一些记录时,它们不起作用,我不明白为什么,我会把代码放在这里也许有人知道。如果我单击按钮,它会向我显示我在活动本体中有100个类但它不会写入我执行同一段代码的文件中。

public void actionPerformed(ActionEvent event) {
    StringBuilder message = new StringBuilder(
            "Get Data from ontology .\n");
    message.append("The active ontology has ");
    message.append(getOWLModelManager().getActiveOntology().getClassesInSignature().size());
    String filename = "C:\\Users\\Onu\\Documents\\GitHub\\protege-plugin-examples\\target\\file.txt";
    int records = getOWLModelManager().getActiveOntology().getClassesInSignature().size();
    try {
        BufferedWriter reader = new BufferedWriter(new FileWriter(filename));
        reader.write(records);
    }
    catch (Exception e)
    {
        System.err.format("Exception occurred trying to read '%s'.", filename);
        e.printStackTrace();
    }
    message.append(" classes.");
    JOptionPane.showMessageDialog(getOWLWorkspace(), message.toString());   
}

1 个答案:

答案 0 :(得分:0)

You need to close the buffered writer after writing, or the program might terminate without saving all data.