Aliza Lang 6 gadus atpakaļ
vecāks
revīzija
88e9410074
4 mainītis faili ar 27 papildinājumiem un 1 dzēšanām
  1. Binārs
      .DS_Store
  2. Binārs
      src/.DS_Store
  3. 27
    1
      src/main/java/Main.java
  4. Binārs
      target/classes/Main.class

Binārs
.DS_Store Parādīt failu


Binārs
src/.DS_Store Parādīt failu


+ 27
- 1
src/main/java/Main.java Parādīt failu

@@ -1,7 +1,33 @@
1
+import java.net.URL;
2
+import java.net.URLConnection;
3
+import java.util.Scanner;
4
+
1 5
 public class Main {
6
+
2 7
     public static void main(String[] args) {
8
+
3 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 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 29
         // print the url
30
+
31
+        System.out.println(content);
6 32
     }
7
-}
33
+}

Binārs
target/classes/Main.class Parādīt failu