JAVA IO问题

yaoyao_qiekenao 2013-01-11 03:13:44
在程序中使用 ImageIO.read( )方法后,程序就停止不运行了,也没有报错。大神在哪儿!~~~求解决思路~~~

代码如下:
File file = new File(filePath+File.separator+ fileName);
if(file.exists()){
ImageIO.read(file);//执行到此处,debug就停止了,不执行下一行
System.out.println(1);
}
...全文
339 14 打赏 收藏 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
Inhibitory 2013-01-12
  • 打赏
  • 举报
回复
    /**
     * Convert the image to an buffered image.
     * @param image An instance of the class Image
     * @return An instance of the class BufferedImage that is converted from an image.
     */
    public static BufferedImage imageToBufferedImage(Image image) {
        int width = image.getWidth(null);
        int height = image.getHeight(null);

        BufferedImage buf = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
        Graphics g = buf.createGraphics();
        g.drawImage(image, 0, 0, width, height, null);
        g.dispose();

        return buf;
    }
xtfgy2012 2013-01-11
  • 打赏
  • 举报
回复
我不觉得是这段代码有问题,你可以把这段代码单独放到一个测试类里去测试下 如果没问题,肯定是方法其他地方的环境影响了它
yaoyao_qiekenao 2013-01-11
  • 打赏
  • 举报
回复
引用 10 楼 Inhibitory 的回复:
ImageIO加载的图片很多时候直接给ConvolveOp进行过滤的时候会出错,格式不对,必须手动的转换成BufferedImage才好用
求 手动转换成bufferedimage的方法。。。
yaoyao_qiekenao 2013-01-11
  • 打赏
  • 举报
回复
引用 9 楼 xtfgy2012 的回复:
能说下你的文件格式吗?
.jpg的文件
Inhibitory 2013-01-11
  • 打赏
  • 举报
回复
ImageIO加载的图片很多时候直接给ConvolveOp进行过滤的时候会出错,格式不对,必须手动的转换成BufferedImage才好用
xtfgy2012 2013-01-11
  • 打赏
  • 举报
回复
能说下你的文件格式吗?
yaoyao_qiekenao 2013-01-11
  • 打赏
  • 举报
回复
引用 5 楼 xtfgy2012 的回复:
文件过大,debug可能会死掉
文件只有100多K的
yaoyao_qiekenao 2013-01-11
  • 打赏
  • 举报
回复
引用 3 楼 xtfgy2012 的回复:
应该是你的图像文件比较大吧
没有,文件只有100多K
yaoyao_qiekenao 2013-01-11
  • 打赏
  • 举报
回复
引用 2 楼 Tnz_ME 的回复:
try catch 用上 扑捉下异常
在项目中已经用了try catch ,但没有报错,没抛出异常。
xtfgy2012 2013-01-11
  • 打赏
  • 举报
回复
文件过大,debug可能会死掉
iLemon 2013-01-11
  • 打赏
  • 举报
回复

我的可以啊
你再试试
xtfgy2012 2013-01-11
  • 打赏
  • 举报
回复
应该是你的图像文件比较大吧
Tnz_ME 2013-01-11
  • 打赏
  • 举报
回复
try catch 用上 扑捉下异常
kk_lucky 2013-01-11
  • 打赏
  • 举报
回复
进入死循环了吧 因为这句一直为真if(file.exists()) 你的read方法写错地方了

62,620

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧