How to convert from File to IFile in java, for files outside the project?

*爱你&永不变心* 提交于 2019-12-20 10:24:16

问题


Normally, this code is used for converting from File to IFile:

IWorkspace workspace= ResourcesPlugin.getWorkspace();    
IPath location= Path.fromOSString(file.getAbsolutePath()); 
IFile ifile= workspace.getRoot().getFileForLocation(location);

But this only works for java files within the project. How can I get the IFile when File file is not in the workspace (not in the project)?


回答1:


IResource and its child IFile were originally meant to be used only for resources located in the workspace. See the Javadoc for IResource.

However, since Eclipse 3.3 there is support for external files as well, see this Eclipse Wiki page.




回答2:


I needed this for using the Binding Resolutions from the Eclipse AST framework. But apparently, this is not possible - for anyone who need it, check this site:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=206391



来源:https://stackoverflow.com/questions/960746/how-to-convert-from-file-to-ifile-in-java-for-files-outside-the-project

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