從插件/RCP中取得文件路徑的方法
作者:hopeshared 引用地址:http://www.aygfsteel.com/hopeshared/archive/2005/12/20/24798.html 最近社區(qū)里問這個(gè)問題的人特別多,所以在這里將自己用到的幾個(gè)方法寫出來。假如以后還有其他的方法,會(huì)進(jìn)行更新。 從插件中獲得絕對(duì)路徑: AaaaPlugin.getDefault().getStateLocation().makeAbsolute().toFile().getAbsolutePath()); 通過文件得到Project: IProject project = ((IFile)o).getProject(); 通過文件得到全路徑: String path = ((IFile)o).getLocation().makeAbsolute().toFile().getAbsolutePath(); 得到整個(gè)Workspace的根: IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); 從根來查找資源: IResource resource = root.findMember(new Path(containerName)); 從Bundle來查找資源: Bundle bundle = Platform.getBundle(pluginId); URL fullPathString = BundleUtility.find(bundle, filePath); 得到Appliaction workspace: Platform.asLocalURL(PRODUCT_BUNDLE.getEntry("")).getPath()).getAbsolutePath(); 得到runtimeworkspace: Platform.getInstanceLocation().getURL().getPath(); 從編輯器來獲得編輯文件: IEditorPart editor = ((DefaultEditDomain)(parent.getViewer().getEditDomain())).getEditorPart(); IEditorInput input = editor.getEditorInput(); if(input instanceof IFileEditorInput){ IFile file = ((IFileEditorInput)input).getFile(); }posted on 2006-12-28 13:37 小牛小蝦 閱讀(275) 評(píng)論(0) 編輯 收藏