package Java;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
public class Io {
public static void main(String[] args) {
try {
//图片地址
URL url = new URL("https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/logo/bd_logo1_31bdc765.png");
URLConnection conn = url.openConnection();
conn.connect();
InputStream is = conn.getInputStream();
BufferedInputStream oi = new BufferedInputStream(is);
FileOutputStream a = new FileOutputStream("D:/2.png");
byte[] buff = new byte[1024 * 4];
int len;
while((len = oi.read(buff)) != -1){
a.write(buff, 0, len);
}
}
catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
转载于:https://www.cnblogs.com/wx1691790309/p/7305009.html