package ttest;
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
public class jietu {
private static URLConnection open;
private static InputStream in;
public static void main(String[] args) throws Exception {
// TODO 自动生成的方法存根
// 1.打开外部网页
String url = "http://p0.so.qhmsg.com/t0193ef441033819585.jpg";
// 2.建立连接
URL url1 = new URL(url);
open = url1.openConnection();//打开连接
open.connect();
// 3.下载资源
in = open.getInputStream();
// 4.将资源写入本地磁盘
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream("E:/beauty.jpg"));
byte[] b = new byte[2048];
int a = -1;
while((a=in.read(b))!=-1){
out.write(b, 0, a);
}
// 5.关闭流
out.flush();
in.close();
out.close();
}
}
从网页中提取图片到本地
最新推荐文章于 2024-04-29 16:31:38 发布