eclipse中项目文件的绝对路径

The*_*aME 1 java eclipse eclipse-plugin

我想rep.xmleclipse插件中打印文件的绝对路径.

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

我试着用它打印file.getLocation().
它回来了C:/Program Files/eclipse/Documents/runtime-EclipseApplication

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

gre*_*449 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
Run Code Online (Sandbox Code Playgroud)

您还可以使用FrameworkUtil获取捆绑包,避免必须硬编码插件ID:

Bundle bundle = FrameworkUtil.getBundle(getClass());
Run Code Online (Sandbox Code Playgroud)

给你Bundle包含给定的类.