简体   繁体   English

从IFile到IResource

[英]IFile to IResource

How can I get an IResource from an IFile or from an absolute path? 如何从IFile或绝对路径获取IResource?

I tried with: 我尝试了:

IWorkspace workspace = ResourcesPlugin.getWorkspace();
IWorkspaceRoot root = workspace.getRoot();
resource = root.findMember(file.getAbsolutePath());

But I get a null value. 但是我得到一个null值。

IFile扩展了IResource ,换句话说, IFileIResource

IFile extends IResource so if you have an IFile you have an IResource . IFile扩展了IResource因此,如果您具有IFile您具有IResource

findMember treats the path it is given as relative to the container (the workspace root in this case). findMember将给定的路径视为相对于容器(在这种情况下为工作空间根目录)的路径。 So you can't use it to find a file given an absolute file path - you must use the findFilesForLocation APIs for that. 因此,您不能使用它来查找具有绝对文件路径的文件-您必须findFilesForLocation使用findFilesForLocation API。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM