通过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