| /home/joey/NetBeansProjects/comp173/src/webpagedisplay/WebPageGrabber.java |
1 package webpagedisplay;
2
3 import java.io.BufferedReader;
4 import java.io.IOException;
5 import java.io.InputStreamReader;
6 import java.net.MalformedURLException;
7 import java.net.URL;
8
9
10
11 @author
12
13
14 public class WebPageGrabber {
15
16
17 @param
18
19 public static void main(String[] args) {
20
21 if(args.length == 0) {
22 System.err.println("Command line arguements needed.");
23 System.exit(-1);
24 }
25
26 for (String s: args) {
27
28 URL urlhandle = null;
29 try {
30 urlhandle = new URL(s);
31 } catch (MalformedURLException ex) {
32 System.err.println("invalid url.");
33 System.err.flush();
34 System.exit(-1);
35 }
36
37 BufferedReader in = null;
38 try {
39 in = new BufferedReader(new InputStreamReader(urlhandle.openStream()));
40 } catch (IOException ex) {
41 System.err.println("Could not contact url.");
42 System.err.flush();
43 System.exit(-1);
44 }
45
46 String inputLine;
47 try {
48 while ((inputLine = in.readLine()) != null) {
49 System.out.println(inputLine);
50 }
51 } catch (IOException ex) {
52 System.err.println("No content found.");
53 System.err.flush();
54 System.exit(-1);
55 }
56
57 try {
58 in.close();
59 } catch (IOException ex) {
60 System.err.println("Could not close the url handler.");
61 System.err.flush();
62 System.exit(-1);
63 }
64
65 }
66 }
67 }
68
69