`
huoyunshen888
  • 浏览: 81747 次
  • 性别: Icon_minigender_1
  • 来自: 西安
社区版块
存档分类
最新评论

JAVA下载网上文件到本地

阅读更多
public static void writeFile(String strUrl, String filePath, String fileName){
try {
URL url = new URL(strUrl);
InputStream is = url.openStream();
File f = new File(filePath);
f.mkdirs();

OutputStream os = new FileOutputStream(filePath + fileName);

int bytesRead = 0;
byte[] buffer = new byte[8192];

while((bytesRead = is.read(buffer,0,8192)) != -1){
os.write(buffer, 0, bytesRead);
}
} catch (Exception e2) {
e2.printStackTrace();
}
}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics