将IFile转换为File [英] Convert IFile to File

查看:152
本文介绍了将IFile转换为File的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 IFile 对象需要用作java.io.File对象。我正在使用以下代码进行转换。

I have a IFile object which need to use as java.io.File object. I am converting using following code.

file = ifile.getFullPath().toFile();

但是调用 file.exists()返回false。

But the call to file.exists() returns false.

推荐答案

您想使用 IResource.getLocation()返回本地文件路径。但是,请仔细阅读javadoc注释,因为您不能假设资源由实际文件支持(它可以是任何东西,具体取决于项目的设置方式)。

You want to use IResource.getLocation() which returns the local file path. However, read the javadoc comments carefully as you cannot assume that a resource is backed by an actual file (it can be anything depending on how the project is set up).

这篇关于将IFile转换为File的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆