java 下载网络中在文件
2018-07-20 来源:open-open
URL url = new URL(Config.local + "/excel/" + name);
HttpURLConnection httpConnection = (HttpURLConnection) url.openConnection();
// 设置请求信息
httpConnection.setRequestProperty("GET", "/down.zip HTTP/1.1");
// 设置接受信息
httpConnection.setRequestProperty("Accept", "image/gif,image/x-xbitmap,application/msword");
// 设置连接信息
httpConnection.setRequestProperty("Connection", "Keep-Alive");
// 获得输入流
InputStream input = httpConnection.getInputStream();
// 创建随机文件
flist.add(new File(name));
RandomAccessFile oSavedFile = new RandomAccessFile(name, "rw");
byte[] b = new byte[1024];
int nRead;
// 从输入流中读入字节流,然后写到文件中
while ((nRead = input.read(b, 0, 1024)) > 0) {
oSavedFile.write(b, 0, nRead);
}
input.close();
oSavedFile.close();
httpConnection.disconnect();
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。
最新资讯
热门推荐