开发者

How to check if an IFile in Java Eclipse Plugin Development really exists?

I want to check, 开发者_JAVA百科if a file exists in an Eclipse workspace.

Therefore I have created an IFile Handle (org.eclipse.core.resources.IFile) via: IFolder.getFile("filename"); I read, that getFile doesn't check if the file really exists.

So how can I check if it exists? Or is the way general way via IFiles and IFolders wrong for that purpose?


IFile inherits IResource#exists() - that should be what you are looking for.


IResource that is the common parent of IFile and IFolder that provides the method exist(). You should use that.


You should call the methods IResource.refreshLocal(..) and then IResource.exists() on your file object.

For me the refreshLocal call was necessary. Otherwise the exists would return false event if the file exists within the file system.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜