标签:图片下载 sys pen audio ati out new 构造 isp
//java 通过url下载图片保存到本地 public static void download(String urlString, int i) throws Exception { // 构造URL URL url = new URL(urlString); // 打开连接 URLConnection con = url.openConnection(); // 输入流 InputStream is = con.getInputStream(); // 1K的数据缓冲 byte[] bs = new byte[1024]; // 读取到的数据长度 int len; // 输出的文件流 String filename = "D:\\图片下载/" + i + ".jpg"; //下载路径及下载图片名称 File file = new File(filename); FileOutputStream os = new FileOutputStream(file, true); // 开始读取 while ((len = is.read(bs)) != -1) { os.write(bs, 0, len); } System.out.println(i); // 完毕,关闭所有链接 os.close(); is.close(); }
标签:图片下载 sys pen audio ati out new 构造 isp
原文地址:https://www.cnblogs.com/pxblog/p/10805342.html