设为首页收藏本站

全球主机交流论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

搜索
热搜: discuz
查看: 409|回复: 1
打印 上一主题 下一主题

是网络故障 还是终端问题 到底哪个东西不对了 我改还不...

[复制链接]

该用户从未签到

跳转到指定楼层
楼主
发表于 2015-6-16 16:13:48 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
/**
* @param httpUrl 网络路径
* @param path        本地路径
*/
public void writefile(String httpUrl, String path) {
// //////////////////////////////读
try {
URL url=new URL(httpUrl);
URLConnection conn = url.openConnection();
conn.setConnectTimeout(5000);//延迟5秒
InputStream datain = conn.getInputStream();
List list = new ArrayList();
int mark = 1;
while (mark != -1) {
byte[] b = new byte[1024];
mark = datain.read(b);
list.add(b);
}
datain.close();
/////////////////////////////////写
File wr_file = new File(path);
FileOutputStream out = new FileOutputStream(wr_file);
BufferedOutputStream buffer = new BufferedOutputStream(out);
DataOutputStream dataout = new DataOutputStream(buffer);
for (int i = 0; i < list.size()-1; i++) {
byte[] out_b = (byte[]) list.get(i);
dataout.write(out_b);
}
dataout.close();
buffer.close();
out.close();
list=null;
} catch (Exception e) {
e.printStackTrace();
}
}
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
收藏收藏
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|中国U网    

GMT+8, 2024-5-15 16:20 , Processed in 0.067653 second(s), 20 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表