您的位置:首页 > 其它

从插件中获取资源的几种方式[总结]_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"文件
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: