zoukankan      html  css  js  c++  java
  • URL网络编程

    package com.atguigu.java1;
    
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.net.HttpURLConnection;
    import java.net.URL;
    
    /**
     * @author shkstart
     * @create 2019 下午 4:54
     */
    public class URLTest1 {
    
        public static void main(String[] args) {
    
            HttpURLConnection urlConnection = null;
            InputStream is = null;
            FileOutputStream fos = null;
            try {
                URL url = new URL("http://localhost:8080/examples/beauty.jpg");
    
                urlConnection = (HttpURLConnection) url.openConnection();
    
                urlConnection.connect();
    
                is = urlConnection.getInputStream();
                fos = new FileOutputStream("day10\beauty3.jpg");
    
                byte[] buffer = new byte[1024];
                int len;
                while((len = is.read(buffer)) != -1){
                    fos.write(buffer,0,len);
                }
    
                System.out.println("下载完成");
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                //关闭资源
                if(is != null){
                    try {
                        is.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
                if(fos != null){
                    try {
                        fos.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
                if(urlConnection != null){
                    urlConnection.disconnect();
                }
            }
    
    
    
    
    
    
        }
    }

  • 相关阅读:
    卡特兰数
    hdu 1023 Train Problem II
    hdu 1022 Train Problem
    hdu 1021 Fibonacci Again 找规律
    java大数模板
    gcd
    object dection资源
    Rich feature hierarchies for accurate object detection and semantic segmentation(RCNN)
    softmax sigmoid
    凸优化
  • 原文地址:https://www.cnblogs.com/lemonzhang/p/12887380.html
Copyright © 2011-2022 走看看