getwebpage.java

来自「java3D game engine design of the source 」· Java 代码 · 共 45 行

JAVA
45
字号

// GetWebPage.java
// Andrew Davison, June 2003, dandrew@ratree.psu.ac.th

/* Retrieve a Web page using a URL object.

  For use through a firewall, use something like:
     java -DproxySet=true -DproxyHost=SOMEHOST -DproxyPort=SOMENUM GetWebPage <url>

  This is packaged up in GetWebPage.bat
*/

import java.net.*;
import java.io.*;


public class GetWebPage 
{

   public static void main(String args[]) throws IOException
   {
     if (args.length != 1) {
       System.out.println("usage:  java GetWebPage <url> ");
       System.exit(0);
     }

     URL url  = new URL(args[0]);
	 BufferedReader br = new BufferedReader(
              new InputStreamReader( url.openStream() ));	
	 
     // print first ten lines of contents
     int numLine = 0;
     String line;
     while ( ((line = br.readLine()) != null) && (numLine <= 10) ) {
       System.out.println(line);
       numLine++;
     }
     if (line != null)
       System.out.println(". . .");

     br.close();                      
   }

} // end of GetWebPage class

⌨️ 快捷键说明

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