如何保存 EMF 模型

How to save an EMF Model

我正在尝试保存扩展名为 .xmi 的 EMF 模型。但是无法这样做,因为我在开发和运行时都看不到任何错误。

如果我将它保存在默认位置 platform:/resource/CompanyToIT/instances/corr-2019_08_31-19_24_52.xmi,它就会被保存。但是当我尝试 select 一个不同的位置时 C:\Users\PC\Desktop\XMI 它不会保存它,因为我看不到该位置的文件(我也尝试添加 platform: 到路径,没有运气).

下面是我正在使用的函数。这是从运行时环境 UI 调用的。 UI 将路径和资源一起传递给此函数。

private void saveModel(Resource r, String time, String newLocation) throws IOException {
        String newPath;
        URI newUri;

        newPath = FilenameUtils.getFullPath(newLocation);           
        newPath += FilenameUtils.getBaseName(newLocation) + "-";
        newPath += time + "." + FilenameUtils.getExtension(newLocation);            
        newUri = URI.createURI(newPath);

        r.setURI(newUri);
        r.save(null);
}

如有任何帮助,我们将不胜感激。谢谢!

您想使用 URI.createFileURI(String that is a filepath).