public static void downLoadImg(String imgName, String imgUrl, String fileURL) throws Exception{
BufferedInputStream in = null;
BufferedOutputStream out = null;
try {
// 创建流
System.out.println("imgUrl:" + imgUrl);
in = new BufferedInputStream( new URL(imgUrl).openStream());
// 生成图片名
int index = imgUrl.lastIndexOf("/");
String sName = imgName == null ? imgUrl.substring(index + 1, imgUrl.length()) : imgName;
File fir = new File(fileURL);
if (!fir.exists()) {
fir.mkdirs();
}
// 存放地址
File img = new File(fileURL + sName);
// 生成图片
out = new BufferedOutputStream( new FileOutputStream(img));
byte[] buf = new byte[2048];
int length = in.read(buf);
while (length != -1) {
out.write(buf, 0, length);
length = in.read(buf);//在一个下载图片的线程有的时候读取到这里就不动了 ,这种问题应该怎么解决
}
} catch (Exception e) {
System.out.println("下载图片异常");
e.printStackTrace();
throw new RuntimeException("下载图片异常");
} finally{
try {
if( in != null){
in.close();
}
if(out != null){
out.flush();
out.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
java 下载图片线程卡死问题,是什么原因, 怎么解决,谢谢
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
5条回答 默认 最新
- lhl_lqc 2015-06-19 04:27关注
打印一些信息调试一个那个地方,看有没有死循环。
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
- ¥15 帮我写一个c++工程
- ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
- ¥15 关于smbclient 库的使用
- ¥15 微信小程序协议怎么写
- ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
- ¥20 怎么用dlib库的算法识别小麦病虫害
- ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
- ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
- ¥15 有了解d3和topogram.js库的吗?有偿请教