浏览代码

Completed?

Chad 6 年前
父节点
当前提交
ede1efdb34
共有 3 个文件被更改,包括 24 次插入3 次删除
  1. 1
    1
      .idea/misc.xml
  2. 23
    2
      src/main/java/Main.java
  3. 二进制
      target/classes/Main.class

+ 1
- 1
.idea/misc.xml 查看文件

@@ -7,5 +7,5 @@
7 7
       </list>
8 8
     </option>
9 9
   </component>
10
-  <component name="ProjectRootManager" version="2" project-jdk-name="1.8" project-jdk-type="JavaSDK" />
10
+  <component name="ProjectRootManager" version="2" project-jdk-name="10" project-jdk-type="JavaSDK" />
11 11
 </project>

+ 23
- 2
src/main/java/Main.java 查看文件

@@ -1,7 +1,28 @@
1
+import jdk.nashorn.api.scripting.URLReader;
2
+
3
+import java.util.Scanner;
4
+import java.net.*;
5
+import java.io.*;
6
+
1 7
 public class Main {
2
-    public static void main(String[] args) {
8
+    public static void main(String[] args) throws Exception{
3 9
         //ask for a url
10
+        System.out.println("What website would you like to fetch?");
11
+        Scanner scanner = new Scanner(System.in);
12
+        String input = scanner.nextLine();
13
+
14
+        URLReader(input);
15
+    }
16
+    public static void URLReader(String input) throws Exception{
17
+
4 18
         // fetch the url
19
+            URL oracle = new URL(input);
20
+            BufferedReader in = new BufferedReader(
21
+                    new InputStreamReader(oracle.openStream()));
5 22
         // print the url
6
-    }
23
+            String inputLine;
24
+            while ((inputLine = in.readLine()) != null)
25
+                System.out.print(inputLine);
26
+            in.close();
27
+        }
7 28
 }

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