在导出的eclipse rcp产品中编写文件

时间:2015-02-17 06:36:32

标签: eclipse-plugin eclipse-rcp

我是新手,我正在研究eclipse-rcp并尝试使用保存在xml文件中的数据构建地址簿。当我运行项目时,它能够读取和写入xml文件,但是当我将它导出到rcp产品中它只读取文件但不能写入。

我尝试搜索Google,但无法找到相关答案,所以我转向了SO。

有什么建议吗?

编辑这是我尝试读取文件并将其写入xml文件的方法

public void writedata() {
    try {
        DocumentBuilderFactory builderFactory = DocumentBuilderFactory
                .newInstance();
        DocumentBuilder builder = builderFactory.newDocumentBuilder();
        Bundle bundle = Platform.getBundle(Activator.PLUGIN_ID);
        URL fileURL = bundle.getEntry("/xmlfiles/person.xml");
        InputStream inputStream=fileURL.openStream();
        Document xmlDocument = builder.parse(inputStream);
        ..................................................
        ..................................................
        ..................................................
        TransformerFactory transformerFactory = TransformerFactory
                .newInstance();
        Transformer transformer = transformerFactory.newTransformer();
        DOMSource source = new DOMSource(xmlDocument);
        Bundle bundle1 = Platform.getBundle(Activator.PLUGIN_ID);
        URL fileURL1 = bundle1.getEntry("/xmlfiles/person.xml");

    StreamResult result = new StreamResult(new File(FileLocator.resolve(fileURL1).getPath())); 
        transformer.transform(source, result);

1 个答案:

答案 0 :(得分:0)

从Eclipse运行应用程序时,它使用插件的扩展项目文件夹。您的XML文件可在此位置写入。

当您作为RCP应用程序导出时,您的插件将打包为插件jar文件,其中包含XML文件。您将无法写入此文件。

要使文件可写,它需要在您的插件项目之外,在RCP应用程序工作区或外部文件夹中。

相关问题