在elipse下写了一个插件,里面要用到icons,本来获取Image可以通过一下方式的:
try{
Image=new Image(null,new FileInputStream("icons/5.gif"));
}
catch(Exception ex)
{
}
注:其中icons这个文件夹在项目根目录下.
但是不知道什么原因,老是出现无法找到系统文件的异常.最后找到了下面的方法:
URL imageURL = Platform.getBundle("com.gujin.aspect").getEntry("icons/5.gif");
Image image = ImageDescriptor.createFromURL(imageURL).createImage();
注:其中com.gujin.aspect是项目名称,icons是项目根目录下的文件夹.