从阿里云下载图片到本地

  @GetMapping(value = "exportImage")
    public void exportImage(){
        try {
            URL url = new URL("http://jianxin-picture.oss-cn-hangzhou.aliyuncs.com/image-file-c500574c-c8a0-42cf-8004-1a248bb9af4e");
            BufferedInputStream in = new BufferedInputStream(url.openStream());

            File file2 = new File("检验.jpg");
            FileOutputStream out = new FileOutputStream(file2);
            int t;
            while ((t = in.read()) != -1) {
                out.write(t);
            }
            out.close();
            in.close();


        } catch (Exception e) {
            e.printStackTrace();
        }
    }

 

posted @ 2022-02-18 13:17  高富贵  阅读(163)  评论(0)    收藏  举报