从插件中获取资源的几种方式[总结]_FileLocator

方式一:
public static URL getFile(String filename) throws IOException {
  System.out.println("get file "  + filename);
  //URL installURL = EditorPlugin.getDefault().getDescriptor().getInstallURL();
  URL installURL = Platform.getBundle("cbg.editor").getEntry("/");//获取id为"cbg.editor"插件的位置
  System.out.println("install url " + installURL);
  //URL mode = Platform.resolve(new URL(installURL, filename));
  return FileLocator.resolve(new URL(installURL, filename));
}

eg:
String filename = "template.xml";
URL url = getFile.getFile("modes/" + filename);//相对路径

方式二:
Bundle bundle = Platform.getBundle(yourPluginId);
Path path = new Path("icons/sample.gif");//注意这里是传的相对路径
URL fileURL = FileLocator.find(bundle, path, null);
InputStream in = fileURL.openStream();

方式三:
InputStream is  is = EditorPlugin.getDefault().getBundle().getEntry("icons/project.gif").openStream();//传的也是相对路径

方式四:
URL url = CorePlugin.getDefault().getBundle().getResource("log4j.properties");
获取CorePlugin插件根目录下的"log4j.properties"文件

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值