Chad 6 gadus atpakaļ
vecāks
revīzija
ede1efdb34
3 mainītis faili ar 24 papildinājumiem un 3 dzēšanām
  1. 1
    1
      .idea/misc.xml
  2. 23
    2
      src/main/java/Main.java
  3. Binārs
      target/classes/Main.class

+ 1
- 1
.idea/misc.xml Parādīt failu

@@ -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 Parādīt failu

@@ -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
 }

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