Normally, this code is used for converting from File
to IFile
:
通常,此代码用于从File转换为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)?
但这仅适用于项目中的java文件。当文件文件不在工作区(不在项目中)时,如何获取IFile?
2 个解决方案
#1
IResource
and its child IFile
were originally meant to be used only for resources located in the workspace. See the Javadoc for IResource.
IResource及其子IFile最初仅用于工作空间中的资源。请参阅Javadoc for IResource。
However, since Eclipse 3.3 there is support for external files as well, see this Eclipse Wiki page.
但是,由于Eclipse 3.3也支持外部文件,请参阅此Eclipse Wiki页面。
#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:
我需要这个来使用Eclipse AST框架的Binding Resolutions。但显然,这是不可能的 - 对于任何需要它的人,请查看此网站:
#1
IResource
and its child IFile
were originally meant to be used only for resources located in the workspace. See the Javadoc for IResource.
IResource及其子IFile最初仅用于工作空间中的资源。请参阅Javadoc for IResource。
However, since Eclipse 3.3 there is support for external files as well, see this Eclipse Wiki page.
但是,由于Eclipse 3.3也支持外部文件,请参阅此Eclipse Wiki页面。
#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:
我需要这个来使用Eclipse AST框架的Binding Resolutions。但显然,这是不可能的 - 对于任何需要它的人,请查看此网站: