java实现下载文件到本地

代码如下:

URL url = new URL("http://www.cnblogs.com/images/logo_small.gif");
        URLConnection con = url.openConnection();
        FileOutputStream out = new FileOutputStream("d:/sss.gif");
        InputStream ins = con.getInputStream();
        byte[] b = new byte[1024];
        int i=0;
        while((i=ins.read(b))!=-1){
            out.write(b, 0, i);
        }
        ins.close();
        out.close();

限时领取免费Java相关资料,涵盖了Java、Redis、MongoDB、MySQL、Zookeeper、Spring Cloud、Dubbo/Kafka、Hadoop、Hbase、Flink等高并发分布式、大数据、机器学习等技术。

资料传送门:https://mp.weixin.qq.com/s/u2b_NVNuMuAPE0w4lc45fw

 

关注下方公众号即可免费领取:

Java碎碎念公众号

原文地址:https://www.cnblogs.com/haha12/p/6197749.html