定义一个接口如下:  
public interface xxx{  
       URL  url  =  xxx.class.getResource("./a");  
}  
然后我想通过变量url利用a目录下的资源。比如a.jpg该怎么办?

解决方案 »

  1.   

    1,网路上的资源,imageURL形如http://......aa.jpg等:
    URL url = new URL(imageURL);
    2,本地资源:imageURL是本地文件
    URL url = new File(imageURL).toURL();然后,
    BufferedImage src = ImageIO.read(url);
    int width = src.getWidth(null);
    int height = src.getHeight(null);
    .......
    别的操作~
      

  2.   

    public interface xxx{  
         public static final URL URL_A_JPG  =  new URL("./a.jpg");