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碎碎念公眾號


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM