简体   繁体   中英

IFile to IResource

How can I get an IResource from an IFile or from an absolute path?

I tried with:

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

But I get a null value.

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

IFile extends IResource so if you have an IFile you have an IResource .

findMember treats the path it is given as relative to the container (the workspace root in this case). So you can't use it to find a file given an absolute file path - you must use the findFilesForLocation APIs for that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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