java - 如何将绝对文件路径传递给 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 的其他解决方案。
我也尝试过其他方式:
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)
解决方案
推荐阅读
- php - 使用 FileTarget 后如何记录错误
- python - 如何按固定的日期列表分组
- swift - 如何删除 Swift 小屏幕上的“safeArea”外观?(背景不是全屏)
- java - Mule - 与数据库的连接失败
- java - 休眠中的子图
- blockchain - 下载所有历史以太坊 ERC721 传输的最佳方式
- jupyter-notebook - 将 Google Drive 挂载到 Python Colab 错误
- c# - 为什么引用类型需要可为空?
- phpmyadmin - 我的 http://localhost/phpmyadmin/ 正在打开一个空白页面
- python - 在添加数字时使用 for 循环遍历列表