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

          作者:hopeshared 引用地址:http://www.aygfsteel.com/hopeshared/archive/2005/12/20/24798.html 最近社區(qū)里問這個問題的人特別多,所以在這里將自己用到的幾個方法寫出來。假如以后還有其他的方法,會進(jìn)行更新。 從插件中獲得絕對路徑: 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 小牛小蝦 閱讀(273) 評論(0)  編輯  收藏


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


          網(wǎng)站導(dǎo)航:
           
          <2006年12月>
          262728293012
          3456789
          10111213141516
          17181920212223
          24252627282930
          31123456

          導(dǎo)航

          統(tǒng)計

          常用鏈接

          留言簿(6)

          隨筆檔案

          文章檔案

          eclipse

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 郧西县| 灵山县| 得荣县| 酒泉市| 额尔古纳市| 皋兰县| 库伦旗| 上杭县| 汝州市| 闵行区| 阜新市| 洪洞县| 玉田县| 绥阳县| 汶川县| 东山县| 苗栗市| 什邡市| 双流县| 鄂尔多斯市| 珠海市| 定结县| 珲春市| 桑日县| 商都县| 湖口县| 巴塘县| 米林县| 紫云| 秀山| 长宁区| 常熟市| 安溪县| 铜陵市| 建始县| 宜昌市| 尚志市| 襄垣县| 井陉县| 新疆| 清徐县|