How to convert from File to IFile in java, for files outside the project?
Question
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)?
Solution 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:
OTHER TIPS
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.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow