简体   繁体   中英

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

I want to check, 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继承了IResource#exists() - 这应该是你要找的东西。

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM