Khalil Malik Saboor 6 年之前
父節點
當前提交
3c14e1a6d1
共有 2 個檔案被更改,包括 20 行新增0 行删除
  1. 20
    0
      src/main/java/Main.java
  2. 二進制
      target/classes/Main.class

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

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

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