Aleena Rose-Mathew hace 6 años
padre
commit
f66d107f10
Se han modificado 5 ficheros con 37 adiciones y 0 borrados
  1. BIN
      .DS_Store
  2. BIN
      src/.DS_Store
  3. BIN
      src/main/.DS_Store
  4. 37
    0
      src/main/java/Main.java
  5. BIN
      target/classes/Main.class

BIN
.DS_Store Ver fichero


BIN
src/.DS_Store Ver fichero


BIN
src/main/.DS_Store Ver fichero


+ 37
- 0
src/main/java/Main.java Ver fichero

@@ -1,7 +1,44 @@
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
 }
44
+

BIN
target/classes/Main.class Ver fichero