Java 如何将绝对文件路径传递到IFile
我希望你们都做得很好。在将绝对文件路径传递给IFile时,我陷入了代码的某些部分。请指导我解决这些问题。我在eclipse中使用Xtend。但是你也可以用java给我提供答案Java 如何将绝对文件路径传递到IFile,java,eclipse,eclipse-plugin,xtend,Java,Eclipse,Eclipse Plugin,Xtend,我希望你们都做得很好。在将绝对文件路径传递给IFile时,我陷入了代码的某些部分。请指导我解决这些问题。我在eclipse中使用Xtend。但是你也可以用java给我提供答案 class A{ def x(){ - val file = new File("D:\\xyz.xml") val ifile = file as IFile // Getting error here new B().y(ifile) } } class B{ def y(IFile f
class A{
def x(){
-
val file = new File("D:\\xyz.xml")
val ifile = file as IFile // Getting error here
new B().y(ifile)
}
}
class B{
def y(IFile file){
//do something
}
}
键入castingjava.io.File时出错,无法将其转换为org.eclipse.core.resources.IFile提前感谢
我尝试过这个解决方案
但我不会屈从于实现我的解决方案。给我一些将绝对路径传递到IFile的其他解决方案
我还尝试了其他方法:
class A{
def x(){
val file = new File("D:\\xyz.xml")
val workspace= ResourcesPlugin.getWorkspace();
val location= Path.fromOSString(file.getAbsolutePath());
val ifile= workspace.root.getFileForLocation(location)
new B().y(ifile)
}
}
class B{
def y(IFile file){
//do somthing
}
}
然后它显示了一些错误,比如工作区关闭线程“main”java.lang.IllegalStateException中的异常:工作区关闭。
但是,在org.eclipse.core.resources.ResourcesPlugin.getWorkspace(ResourcesPlugin.java:412)中,您为该解决方案实现的代码不在这里。你能证明这一点吗?我已经编辑了我的查询。“工作区是关闭的”通常意味着你试图在一个普通的Java程序中使用这段代码-工作区只在安装在Eclipse或RCP(或无头RCP)中的Eclipse插件中工作。此外,IFile仅适用于工作区中的一个文件-它不能只是任何文件。@greg-449感谢您的回复。我试试看。