Convert from absolute path to IFile

不问归期 提交于 2019-12-24 09:27:17

问题


I am working at an eclipse plugin where the projects which exist in the Project Explorer view have a different workspace name than the actual path of the project. So considering a project located at D:\test when I try to get the project location, it points to D:\test_plugin_specific_suffix.

Is there a way to get an IFile from an absolute path (which points to the local path, D:\test\testfile.txt)?

I want to create a hyperlink to a specific file for which I have the absolute path. When I click on console on the hyperlink it should open in the editor the file.


回答1:


You can use IWorkspaceRoot.findFilesForLocationURI to find the IFile corresponding to a absolute path (there might be more than one if you are using links):

File file = new File(....absolue path);
URI location = file.toURI();
IFile[] files = ResourcesPlugin
   .getWorkspace()
   .getRoot()
   .findFilesForLocationURI( location );


来源:https://stackoverflow.com/questions/47139578/convert-from-absolute-path-to-ifile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!