从插件中获取资源的几种方式[总结]_FileLocator
2012-09-05 17:05
501 查看
方式一:
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"文件
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"文件
相关文章推荐
- Struts2获取web资源的几种方式
- 总结Struts2获取servletAPI的几种方式
- 探讨跨域请求资源的几种方式(总结)
- 尚硅谷公开课--struts2--3--struts2中获取web资源的几种方式
- 获取url资源的几种方式
- Android 获取图片资源的几种方式
- [总结]Android 获取本地视频文件路径并播放的几种方式
- Android 中获取图片资源的几种方式
- android 获取当前时间的几种方式,总结
- java-- servlet获取资源的几种方式
- 基于$.ajax()方法从服务器获取json数据的几种方式总结
- (android插件)获取jar包中的资源总结
- Android学习——maven插件的安装以及关联源码的几种方式总结
- 总结C# 获取DPI的几种方式
- Spring Boot获取前端页面参数的几种方式总结
- 【Android】获取Bitmap的几种方式总结
- Struts2获取web资源的几种方式
- Spring Boot获取前端页面参数的几种方式总结
- struts2学习笔记--总结获取servletAPI的几种方式
- 获取Bitmap的几种方式总结