您的位置:首页 > 理论基础 > 计算机网络

从网络上下载文件

2020-02-03 03:01 585 查看

public void downloadNet() throws MalformedURLException {

URL url = new URL("webUrl");

try {
URLConnection conn = url.openConnection();
InputStream inStream = conn.getInputStream();
FileOutputStream fs = new FileOutputStream("fileUrl");

byte[] buffer = new byte[1204];
int length = 0;
while ((length = inStream.read(buffer)) != -1) {
fs.write(buffer, 0, length);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

}

  • 点赞
  • 收藏
  • 分享
  • 文章举报
她说叫随便 发布了10 篇原创文章 · 获赞 0 · 访问量 93 私信 关注
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: