从绝对路径转换为IFile [英] Convert from absolute path to IFile
问题描述
我正在使用一个eclipse插件,其中 Project Explorer
视图中存在的项目的工作区名称与项目的实际路径不同。因此,当我尝试获取位于 D:\test
的项目时,它指向 D:\test_plugin_specific_suffix
。
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
.
是否可以从绝对路径(指向本地路径 D:\)获取IFile? test\testfile.txt
)?
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.
推荐答案
您可以使用 IWorkspaceRoot.findFilesForLocationURI
来找到与绝对路径相对应的 IFile
(如果使用链接的
可能有多个) :
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 );
这篇关于从绝对路径转换为IFile的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!