Browse Source

fido is fetching

Shivam Patel 6 years ago
parent
commit
7bc2e2a316
2 changed files with 36 additions and 0 deletions
  1. 36
    0
      src/main/java/Main.java
  2. BIN
      target/classes/Main.class

+ 36
- 0
src/main/java/Main.java View File

@@ -1,7 +1,43 @@
1
+import java.net.MalformedURLException;
2
+import java.net.URL;
3
+import java.net.URLConnection;
4
+import java.util.Scanner;
5
+
1 6
 public class Main {
2 7
     public static void main(String[] args) {
3 8
         //ask for a url
9
+        Scanner scan = new Scanner(System.in);
10
+
11
+        System.out.println("enter URL: ");
12
+        String url = scan.nextLine();
13
+        System.out.println("fetching..." );
4 14
         // fetch the url
15
+        String link = null;
16
+        URLConnection connection = null;
17
+        try {
18
+            connection =  new URL("https://" + url).openConnection();
19
+            Scanner urlScanner = new Scanner(connection.getInputStream());
20
+            urlScanner.useDelimiter("\\Z");
21
+
22
+            link = urlScanner.next();
23
+        }
24
+        catch (MalformedURLException e) {
25
+            e.printStackTrace();
26
+
27
+        }
28
+        catch (Exception e){
29
+            e.printStackTrace();
30
+
31
+        }
32
+        System.out.println(link);
33
+
34
+
35
+
36
+
5 37
         // print the url
38
+
39
+
40
+
41
+
6 42
     }
7 43
 }

BIN
target/classes/Main.class View File