码迷,mamicode.com
首页 > 编程语言 > 详细

java http下载文件

时间:2014-12-09 19:02:12      阅读:246      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   io   color   sp   for   java   on   

private boolean downloadFile(String httpUrl, String savePath) {
        int byteread = 0;
        try {
            URL url = new URL(httpUrl);
            URLConnection conn = url.openConnection();
            InputStream inStream = conn.getInputStream();
            FileOutputStream fs = new FileOutputStream(savePath);
            byte[] buffer = new byte[1204];
            while ((byteread = inStream.read(buffer)) != -1) {
                fs.write(buffer, 0, byteread);
            }
            System.out.println(savePath+" download finished!");
            return true;
        } catch (MalformedURLException e) {
            e.printStackTrace();
            return false;
        } catch (IOException e) {
            e.printStackTrace();
            return false;
        }
    }

 

java http下载文件

标签:style   blog   http   io   color   sp   for   java   on   

原文地址:http://www.cnblogs.com/zhangfei/p/4153797.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!