集册 Java实例教程 从URL连接读取

从URL连接读取

欢马劈雪     最近更新时间:2020-01-02 10:19:05

510
从URL连接读取
/**来 自 N o  w  J a v a . c o m - 时  代  Java**/

import java.net.*;

import java.io.*;


public class URLConnectionReader {

    public static void main(String[] args) throws Exception {

        URL yahoo = new URL("http://www.yahoo.com/");

        URLConnection yahooConnection = yahoo.openConnection();

        BufferedReader in = new BufferedReader(new InputStreamReader(

                yahooConnection.getInputStream()));

        String inputLine;


        while ((inputLine = in.readLine()) != null)

            System.out.println(inputLine);


        in.close();

    }

}


展开阅读全文