Skip to content

Instantly share code, notes, and snippets.

@suxiaogang
Last active December 15, 2015 16:29
Show Gist options
  • Save suxiaogang/5289991 to your computer and use it in GitHub Desktop.
Save suxiaogang/5289991 to your computer and use it in GitHub Desktop.
File <-> IFile
//File > IFile:
IContainer[] findContainersForLocationURI = ResourcesPlugin.getWorkspace().getRoot().findContainersForLocationURI(
file.toURI());
IFile[] findFilesForLocationURI = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocationURI(filefile.toURI());
//IFile > File:
IProject fsProject = ResourceModelUtils.getProject(project);
IFolder tmpFolder = ResourceUtils.getFolder(fsProject, RepositoryConstants.TEMP_DIRECTORY, true);
String tmpFilename = "DOC" + documentationItem.getProperty().getId();
IFile fileTmp = tmpFolder.getFile(tmpFilename);//Get IFile reference by file name;
File file = fileTmp.getLocation().toFile(); //Get File reference by IFile reference.
File newFile = new File(fileTmp.getLocation().toOSString()); //Convert IFile to File.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment