imageIO给出错误?

时间:2012-03-15 08:58:21

标签: java image

 public BufferedImage readImage(String fileLocation) {
        BufferedImage img = null;

        File file = new File("D:\\logo.jpg");
            img = ImageIO.read(file);
}

抛出错误可以;读取文件

1 个答案:

答案 0 :(得分:0)

代码应如下所示,

BufferedImage img = null;
try {
     img = ImageIO.read(new File("D:\\logo.jpg"));
} catch (IOException e) {
      System.out.println("Exception is --- "+ e.getMessage());
      e.printStackTrace();
}

然后,如果发生异常,您可以在打印消息和堆栈跟踪时跟踪问题的实际原因。