【问题标题】:writing files in exported eclipse rcp product在导出的 eclipse rcp 产品中写入文件
【发布时间】:2015-02-17 21:31:00
【问题描述】:

我是一个新手,我正在使用 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);

【问题讨论】:

    标签: eclipse-plugin eclipse-rcp


    【解决方案1】:

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

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

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

    【讨论】:

    • 感谢 nick..它有效..我将文件保存在我的 Eclipse 产品文件夹中
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-26
    • 2012-06-22
    • 2018-02-10
    • 1970-01-01
    • 2019-12-09
    • 1970-01-01
    相关资源
    最近更新 更多