Vincent Sima 6 年前
父节点
当前提交
0d970599b7
共有 2 个文件被更改,包括 21 次插入0 次删除
  1. 21
    0
      src/main/java/Main.java
  2. 二进制
      target/classes/Main.class

+ 21
- 0
src/main/java/Main.java 查看文件

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

二进制
target/classes/Main.class 查看文件