printurlpage.java

来自「java 完全探索的随书源码」· Java 代码 · 共 61 行

JAVA
61
字号
import java.net.*;import java.io.*;public class PrintURLPage{  // Default Constructor  public PrintURLPage()  {    super();  }  // Read the HTML page  public void printHTMLPage( String urlStr )  {    URL url = null;    BufferedReader reader = null;    String data = null;    try    {      // Create the URL object      url = new URL( urlStr );      // Decorate the input stream with something easier to use      reader = new BufferedReader( new InputStreamReader(url.openStream()) );      // Keep reading lines until there are no more to read      while( (data = reader.readLine()) != null )      {        // Just write out the text to the console        System.out.println( data );      }    }    catch( MalformedURLException ex )    {      ex.printStackTrace();    }    catch( IOException ex )    {      ex.printStackTrace();    }  }  // Start the example  public static void main( String args[] )  {    if ( args.length == 0 )    {      System.out.println( "Usage: java PrintURLPage http://<url>" );      System.exit( 0 );    }    // Get the url passed in on the command line    String url = args[0];    PrintURLPage f = new PrintURLPage();    // Get and print the url passed in    f.printHTMLPage( url );  }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?