|
@@ -1,7 +1,27 @@
|
|
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
|
4
|
|
- // fetch the url
|
5
|
|
- // print the url
|
|
7
|
+ System.out.println("Enter an URl");
|
|
8
|
+ Scanner scanner = new Scanner(System.in);
|
|
9
|
+ String url = scanner.nextLine().trim();
|
|
10
|
+ //ask for a url
|
|
11
|
+ System.out.println("Fetching " + url);
|
|
12
|
+ // fetch the url
|
|
13
|
+ String content = null;
|
|
14
|
+ URLConnection connection = null;
|
|
15
|
+ try {
|
|
16
|
+ connection = new URL("https://"+url).openConnection();
|
|
17
|
+ scanner = new Scanner(connection.getInputStream());
|
|
18
|
+ scanner.useDelimiter("\\Z");
|
|
19
|
+ content = scanner.next();
|
|
20
|
+ }catch ( Exception ex ) {
|
|
21
|
+ ex.printStackTrace();
|
|
22
|
+ }
|
|
23
|
+ System.out.println(content);
|
|
24
|
+ //print url
|
|
25
|
+ }
|
|
26
|
+
|
6
|
27
|
}
|
7
|
|
-}
|