
@Test
public void d() throws IOException{
URL url = new URL("http://baidu.com");
InputStream inputStream;
URLConnection urlConnection = url.openConnection();
inputStream = urlConnection.getInputStream();
int len;
// byte[] bytes = new byte[1024];
// while((len = inputStream.read(bytes)) != -1){
// System.out.println(new String(bytes, 0, len, StandardCharsets.UTF_8));
// }
// InputStreamReader inputStreamReader = new InputStreamReader(inputStream, StandardCharsets.UTF_8);
//
// char[] chars = new char[1024];
//
// while((len = inputStreamReader.read(chars)) != -1){
// System.out.println(new String(chars, 0, len));
// }
//
// inputStreamReader.close();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8));
String line;
while((line=bufferedReader.readLine())!=null){
System.out.println("line = " + line);
}
}
