zoukankan      html  css  js  c++  java
  • 从网页下载图片的代码

    import java.io.BufferedOutputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.net.MalformedURLException;
    import java.net.URL;
    import java.net.URLConnection;
    
    public class DownLoad {
        public static void main(String[]args){
            try {
                URL url = new URL("https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/logo/bd_logo1_31bdc765.png");
                try {
                URLConnection bd= url.openConnection();
                InputStream in = bd.getInputStream();
                
                BufferedOutputStream bo = new BufferedOutputStream(new FileOutputStream("D:/baiduCopy.png"));
                byte[]b= new byte[1024];
                int n=-1;
                while((n=in.read(b))!=-1){
                    bo.write(b, 0, n);
                }
                in.close();
                bo.close();
                
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            } catch (MalformedURLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        
            
        }
    }
  • 相关阅读:
    ssh.sh_for_ubuntu1604
    ssh.sh_for_ubuntu1404
    ssh.sh_for_ubuntu1204
    ssh.sh_for_centos
    raw,cow,qcow,qcow2镜像的比较
    Oz 创建Windows2008R2镜像
    Oz 创建Ubuntu镜像
    Oz 创建Debian8镜像
    Oz 创建CentOS7镜像
    Oz 创建CentOS6镜像
  • 原文地址:https://www.cnblogs.com/-strong/p/7300916.html
Copyright © 2011-2022 走看看