|
@@ -1,7 +1,30 @@
|
|
1
|
+import java.net.URL;
|
|
2
|
+import java.net.URLConnection;
|
|
3
|
+import java.util.Scanner;
|
|
4
|
+
|
1
|
5
|
public class Main {
|
2
|
6
|
public static void main(String[] args) {
|
3
|
|
- //ask for a url
|
|
7
|
+ System.out.println("enter a url");
|
|
8
|
+
|
|
9
|
+ //ask for url
|
|
10
|
+ Scanner scanner = new Scanner(System.in);
|
|
11
|
+ String url = scanner.nextLine().trim();
|
|
12
|
+ System.out.println("Fetching " + url);
|
|
13
|
+
|
4
|
14
|
// fetch the url
|
|
15
|
+ String content = null;
|
|
16
|
+ URLConnection connection = null;
|
|
17
|
+ try {
|
|
18
|
+ connection = new URL(url).openConnection();
|
|
19
|
+ Scanner urlscanner = new Scanner(connection.getInputStream());
|
|
20
|
+ urlscanner.useDelimiter("\\Z");
|
|
21
|
+ content = urlscanner.next();
|
|
22
|
+ }catch ( Exception ex ) {
|
|
23
|
+ ex.printStackTrace();
|
|
24
|
+ }
|
|
25
|
+
|
|
26
|
+ System.out.println(content);
|
|
27
|
+
|
5
|
28
|
// print the url
|
6
|
29
|
}
|
7
|
30
|
}
|