eclipse中项目文件的绝对路径

时间:2014-10-30 11:46:18

标签: java eclipse eclipse-plugin

我想在 eclipse插件中打印文件rep.xml的绝对路径。

我已将文件rep.xml放在路径
C:\Program Files\Eclipse\Documents\Eclipse\samplePlugin\resources\rep.xml.

我尝试使用file.getLocation()进行打印 它返回C:/Program Files/eclipse/Documents/runtime-EclipseApplication

如何在eclipse中打印绝对路径。请帮忙。

1 个答案:

答案 0 :(得分:5)

如果您想阅读插件中的文件,请使用以下命令:

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

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

URL fileUrl = FileLocator.toFileURL(url);

File file = new File(fileUrl.getFile());

... read file using normal Java file APIs

您还可以使用FrameworkUtil来获取捆绑包,从而避免对插件ID进行硬编码:

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

为您提供包含给定类的Bundle

相关问题