Aliza Lang 6 anni fa
parent
commit
88e9410074
4 ha cambiato i file con 27 aggiunte e 1 eliminazioni
  1. BIN
      .DS_Store
  2. BIN
      src/.DS_Store
  3. 27
    1
      src/main/java/Main.java
  4. BIN
      target/classes/Main.class

BIN
.DS_Store Vedi File


BIN
src/.DS_Store Vedi File


+ 27
- 1
src/main/java/Main.java Vedi File

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

BIN
target/classes/Main.class Vedi File