`

[zt]从插件/RCP中取得文件路径的方法

阅读更多

FROM:http://www.blogjava.net/hopeshared/archive/2005/12/20/24798.aspx

最近社区里问这个问题的人特别多,所以在这里将自己用到的几个方法写出来。假如以后还有其他的方法,会进行更新。

从插件中获得绝对路径:       
java 代码
  1. AaaaPlugin.getDefault().getStateLocation().makeAbsolute().toFile().getAbsolutePath());  


通过文件得到Project:
java 代码
  1. IProject project = ((IFile)o).getProject();  


通过文件得到全路径:
java 代码
  1. String path = ((IFile)o).getLocation().makeAbsolute().toFile().getAbsolutePath();   


得到整个Workspace的根:
java 代码
  1. IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();  



从根来查找资源:

java 代码
  1. IResource resource = root.findMember(new Path(containerName));  


从Bundle来查找资源:

java 代码
  1. Bundle bundle = Platform.getBundle(pluginId);   
  2. URL fullPathString = BundleUtility.find(bundle, filePath);  

得到Appliaction workspace:

从编辑器来获得编辑文件

java 代码
  1. IEditorPart editor = ((DefaultEditDomain)(parent.getViewer().getEditDomain())).getEditorPart();   
  2. IEditorInput input = editor.getEditorInput();   
  3. if(input instanceof IFileEditorInput){   
  4.   IFile file = ((IFileEditorInput)input).getFile();   
  5. }  
java 代码
  1. Platform.asLocalURL(PRODUCT_BUNDLE.getEntry("")).getPath()).getAbsolutePath();  


得到runtimeworkspace:
 
java 代码
  1. Platform.getInstanceLocation().getURL().getPath();  
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics