编程语言
首页 > 编程语言> > Java已知图片路径下载图片到本地

Java已知图片路径下载图片到本地

作者:互联网

 public static void main(String[] args)
    {
        FileOutputStream fos = null;
        BufferedInputStream bis = null;
        HttpURLConnection httpUrl = null;
        int size = 0;
        byte[] buf = new byte[1024];

        File file = new File("E:/" + "1.jpg");
        try
        {
            URL url = new URL("https://images.cnblogs.com/cnblogs_com/qq1445496485/1909145/o_2103030645361045.jpg");
            httpUrl = (HttpURLConnection)url.openConnection();
            httpUrl.connect();
            bis = new BufferedInputStream(httpUrl.getInputStream());
            fos = new FileOutputStream(file);
            while ((size = bis.read(buf)) != -1)
            {
                fos.write(buf, 0, size);
            }
            fos.flush();
            fos.close();
            bis.close();
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }

    }

 

标签:size,Java,fos,路径,httpUrl,new,null,bis,图片
来源: https://www.cnblogs.com/qq1445496485/p/14844464.html