123456789101112131415161718192021222324252627
  1. import java.io.InputStreamReader;
  2. import java.net.URL;
  3. import java.net.URLConnection;
  4. import java.util.Scanner;
  5. public class URLExpSimple {
  6. public static void main(String[] args) {
  7. try {
  8. URL mySite = new URL("http://www.cs.utexas.edu/~scottm");
  9. URLConnection yc = mySite.openConnection();
  10. Scanner in = new Scanner(new InputStreamReader(yc.getInputStream()));
  11. int count = 0;
  12. while (in.hasNext()) {
  13. System.out.println(in.next());
  14. count++;
  15. }
  16. System.out.println("Number of tokens: " + count);
  17. in.close();
  18. } catch (Exception e) {
  19. e.printStackTrace();
  20. }
  21. }
  22. }