方式一:
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"文件