eclipse插件运行时获取文件路径

来源:互联网 发布:容易猝死的职业知乎 编辑:程序博客网 时间:2024/06/07 00:50

通过FileSystem获取插件运行时的文件和文件夹。

public static File toLocalFile(String folderName){          try {              URL url = Activator.getDefault().getBundle().getEntry(folderName);              url = FileLocator.toFileURL(url);              IFileSystem fs = EFS.getLocalFileSystem();              IFileStore file = fs.getStore(new Path(url.getPath()));              IFileStore fileStore = file.getFileStore(new Path(""));              File file2 =  fileStore.toLocalFile(EFS.NONE, null);                           return file2;          } catch (IOException e) {              e.printStackTrace();          } catch (CoreException e) {              e.printStackTrace();          }          return null;      }  

需要把org.eclipse.core.filesystem这个jar包加入lib中,还要在dependencies选项卡中把这个jar包添加进去,否则会报classnotfoundexception。

转载自:qq123zhz

0 0