Source of URLReader.java


  1: //URLReader.java
  2: 
  3: import java.util.Scanner;
  4: import java.io.InputStreamReader;
  5: import java.net.URL;
  6: 
  7: public class URLReader
  8: {
  9:     public static void main(String[] args) throws Exception
 10:     {
 11:         URL website = new URL("http://cs.smu.ca/webbook2e/ch02/first.txt");
 12:         Scanner inputStream = new Scanner(
 13:             new InputStreamReader(website.openStream()));
 14: 
 15:         while (inputStream.hasNextLine())
 16:         {
 17:             String s = inputStream.nextLine();
 18:             System.out.println(s);
 19:         }
 20:         inputStream.close();
 21:         Scanner keyboard = new Scanner(System.in);
 22:         System.out.print("Press Enter to continue ... ");
 23:         keyboard.nextLine();
 24:     }
 25: }
 26: