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