如何使用 java 读取 Eclipse rcp 应用程序中的 .xml 文件路径?

How to read the .xml file path in Eclipse rcp application using java?

我发现 solution.This 解决方案将帮助我从适当的文件夹路径读取文件。 **

String resourceFolder=""; URL url=new URL("platform:/plugin/com.example"+resourceFolder); String resourceFolderPath=org.eclipse.core.runtime.FileLocator.toFileURL(url).getPath(); resourceFile=resourceFolderPath+"xxxx.xml";

**

还有其他方法可以找到吗?

FileLocator 是用于访问插件资源的正确 API。

使用FileLocator.find获取资源URL:

URL url = FileLocator.find(bundle, new Path("relative path in plugin"), null);

bundle 是插件的 Bundle。对于当前插件,您可以使用:

Bundle bundle = FrameworkUtil.getBundle(getClass());

要获取不同插件的捆绑包,请使用:

Bundle bundle = Platform.getBundle("plugin id");

find返回的URL是一个bundleentryURL。您可以在此使用 openStream 来读取资源。

如果您想要 file URL,您可以使用以下方式转换 url:

URL fileURL = FileLocator.toFileURL(url);

这可能会导致 Eclipse 将资源复制到临时位置的文件中。