用JAVA爬取网络上的一些简单资源
原创
©著作权归作者所有:来自51CTO博客作者Frank___7的原创作品,请联系作者获取转载授权,否则将追究法律责任
package com.kuang.demo04;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
public class URLDemo01 {
public static void main(String[] args) throws IOException {
URL url = new URL("https://www.baidu.com/img/baidu_85beaf5496f291521eb75ba38eacbd87.svg");
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
InputStream in = urlConnection.getInputStream();
FileOutputStream Fout = new FileOutputStream("1.svg");
byte[] buff = new byte[1024];
int len;
while ((len = in.read(buff)) != -1) {
Fout.write(buff, 0, len);
}
Fout.close();
in.close();
urlConnection.disconnect();
}
}
```java
在这里插入代码片