最近社區(qū)里問(wèn)這個(gè)問(wèn)題的人特別多,所以在這里將自己用到的幾個(gè)方法寫出來(lái)。假如以后還有其他的方法,會(huì)進(jìn)行更新。
從插件中獲得絕對(duì)路徑:
AaaaPlugin.getDefault().getStateLocation().makeAbsolute().toFile().getAbsolutePath());
IProject project = ((IFile)o).getProject();
String path = ((IFile)o).getLocation().makeAbsolute().toFile().getAbsolutePath();
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IResource resource = root.findMember(new Path(containerName));
Bundle bundle = Platform.getBundle(pluginId);
URL fullPathString = BundleUtility.find(bundle, filePath);
Platform.asLocalURL(PRODUCT_BUNDLE.getEntry("")).getPath()).getAbsolutePath();
得到runtimeworkspace:
Platform.getInstanceLocation().getURL().getPath();
從編輯器來(lái)獲得編輯文件
IEditorPart editor = ((DefaultEditDomain)(parent.getViewer().getEditDomain())).getEditorPart();
IEditorInput input = editor.getEditorInput();
if(input instanceof IFileEditorInput){
IFile file = ((IFileEditorInput)input).getFile();
}
從插件中獲得絕對(duì)路徑:

通過(guò)文件得到Project:

通過(guò)文件得到全路徑:


得到整個(gè)Workspace的根:

從根來(lái)查找資源:

從Bundle來(lái)查找資源:



得到Appliaction workspace:

得到runtimeworkspace:

從編輯器來(lái)獲得編輯文件





dm520