BlackJack 6 年之前
父節點
當前提交
2ea1fe8021
共有 1 個文件被更改,包括 11 次插入4 次删除
  1. 11
    4
      src/main/java/Main.java

+ 11
- 4
src/main/java/Main.java 查看文件

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