import java.io.*;
import java.net.*;
import java.util.*;
import javax.swing.plaf.synth.SynthSpinnerUI;
public class java0807testnew {
private static URLConnection openConnection;
public static void main(String[] args) throws IOException, ClassNotFoundException {
//读取网站图片
//1.先复制网站图片的地址
URL url = new URL("https://www.baidu.com/img/bd_logo1.png");
//2.打开连接
URLConnection openConnection = url.openConnection();
openConnection.connect();
//3.获取流
InputStream in = openConnection.getInputStream();
FileOutputStream fout = new FileOutputStream("D:/233.png");
BufferedOutputStream bout = new BufferedOutputStream(fout);
//按字节读写!!!
int data = in.read() ;
while(data!=-1){
bout.write(data); //上面已经读了一次,所以现在应该先写
data = in.read();
}
// byte []b = new byte[1024];
// int len = -1;
// while((len=in.read(b))!=-1){
// bout.write(b,0,len);
// }
in.close();
bout.flush();
fout.close();
bout.close();
}
}
import java.net.*;
import java.util.*;
import javax.swing.plaf.synth.SynthSpinnerUI;
public class java0807testnew {
private static URLConnection openConnection;
public static void main(String[] args) throws IOException, ClassNotFoundException {
//读取网站图片
//1.先复制网站图片的地址
URL url = new URL("https://www.baidu.com/img/bd_logo1.png");
//2.打开连接
URLConnection openConnection = url.openConnection();
openConnection.connect();
//3.获取流
InputStream in = openConnection.getInputStream();
FileOutputStream fout = new FileOutputStream("D:/233.png");
BufferedOutputStream bout = new BufferedOutputStream(fout);
//按字节读写!!!
int data = in.read() ;
while(data!=-1){
bout.write(data); //上面已经读了一次,所以现在应该先写
data = in.read();
}
// byte []b = new byte[1024];
// int len = -1;
// while((len=in.read(b))!=-1){
// bout.write(b,0,len);
// }
in.close();
bout.flush();
fout.close();
bout.close();
}
}