欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

下载网络资源

程序员文章站 2022-03-02 21:13:01
...
 public static void UrlDown() {
        URL url = null;
        String filePath = "";
        try {
            url = new URL("https://dss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/topnav/[email protected]");
            HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
            InputStream inputStream = urlConnection.getInputStream();
            filePath="1.png";
            FileOutputStream fos = new FileOutputStream(filePath);
            byte[] buffer = new byte[1024];
            int len;
            while ((len = inputStream.read(buffer)) != -1) {
                fos.write(buffer, 0, len);//写出
            }
            fos.close();
            inputStream.close();
            urlConnection.disconnect();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
相关标签: springboot java