首页 > 解决方案 > 如何将绝对文件路径传递给 IFile

问题描述

我希望你们都做得很好。在将绝对文件路径传递给 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 file){

  //do something

 }
}

当类型转换java.io.File 无法转换为 org.eclipse.core.resources.IFile时出现错误 ,提前谢谢你。

我试过这个解决方案

从绝对路径转换为 ​​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
 }
}

然后它显示一些错误,例如 Workspace is closed 线程“main”中的异常 java.lang.IllegalStateException: Workspace is closed。在 org.eclipse.core.resources.ResourcesPlugin.getWorkspace(ResourcesPlugin.java:412)

标签: javaeclipseeclipse-pluginxtend

解决方案


推荐阅读