首页 > 技术文章 > Eclipse插件开发中File和IFile的转换

Soy-technology 2019-08-29 10:37 原文

(1) File转IFile

  第一种方法:

    IFile[] ifile = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocationURI(file.toURI());

  第二种方法:

    String filepath =file.getPath();

    IProject proj =ResourcesPlugin.getWorkspace().getRoot().getProject(projName);

    String path =filepath.substring(proj.getLocation().toString().length() + 1);

    IFile file =proj.getFile(path);  

(2) IFile转File

  File file = ifile.getLocation().toFile;

    或者

  File = newFile(ifile.getLocation().toOSString);   

推荐阅读