Java代码爬取完整图片简单工具类

util工具类

 public void method01() throws Exception {
        URL url1 = new URL("http://pic327.nipic.com/file/20200921/24834673_104056152000_2.jpg");
        URLConnection uc = url1.openConnection();
        InputStream inputStream = uc.getInputStream();
        FileOutputStream out = new FileOutputStream("D:\\image\\a.jpg");
        int j = 0;
        while ((j = inputStream.read()) != -1) {
            out.write(j);
            System.out.println("图片爬取成功");
        }
        inputStream.close();
    }

 

posted @ 2020-10-14 10:25  lzyuan0601  阅读(144)  评论(0)    收藏  举报