從插件/RCP中取得文件路徑的方法

          作者:hopeshared 引用地址:http://www.aygfsteel.com/hopeshared/archive/2005/12/20/24798.html 最近社區里問這個問題的人特別多,所以在這里將自己用到的幾個方法寫出來。假如以后還有其他的方法,會進行更新。 從插件中獲得絕對路徑: AaaaPlugin.getDefault().getStateLocation().makeAbsolute().toFile().getAbsolutePath()); 通過文件得到Project: IProject project = ((IFile)o).getProject(); 通過文件得到全路徑: String path = ((IFile)o).getLocation().makeAbsolute().toFile().getAbsolutePath(); 得到整個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) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          <2006年12月>
          262728293012
          3456789
          10111213141516
          17181920212223
          24252627282930
          31123456

          導航

          統計

          常用鏈接

          留言簿(6)

          隨筆檔案

          文章檔案

          eclipse

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 项城市| 丹巴县| 依安县| 晴隆县| 周宁县| 措美县| 北辰区| 清徐县| 嘉禾县| 昭平县| 千阳县| 营山县| 普定县| 永昌县| 雷州市| 云梦县| 兴城市| 丰镇市| 达日县| 九寨沟县| 龙陵县| 樟树市| 滦南县| 叙永县| 云和县| 盐池县| 渑池县| 祥云县| 大冶市| 邢台县| 舒城县| 凤翔县| 扎鲁特旗| 黔江区| 永登县| 浦江县| 郎溪县| 滨州市| 龙州县| 晋江市| 蕉岭县|