使用URL类打印网页内容

import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.Socket;
import java.net.URL;
import java.util.Scanner;


public class UrlTest {
    public static void main(String[] args) throws IOException{
    URL url = new URL("http://www.baidu.com/");
    InputStream in = url.openStream();
    Scanner s = new Scanner(in);
    while(s.hasNextLine())
        System.out.println(s.nextLine());
    
    }
}
原文地址:https://www.cnblogs.com/qqjue/p/2502605.html