URLConnectionReaderDemo 类及其 main()方法

来源:互联网 发布:python 中英文摘要 编辑:程序博客网 时间:2024/06/05 00:22
import java.net.*;
import java.io.*;
public class URLConnectionReaderDemo{
public static void main(String[] args) throws Exception {
URL wyURL = new URL("http://www.163.com/"); //创建 URL 对象
URLConnection con = wyURL.openConnection();
//获得 URLConnection 对象
BufferedReader in = new BufferedReader(
new InputStreamReader(
con.getInputStream()));
//从连接对象获得输入流
String inputLine;
while ((inputLine = in.readLine()) != null)
//从输入流一行行读取 URL 的内容
System.out.println(inputLine);
//输出到控制台
in.close();
//关闭输入流
}
}
0 0