Procházet zdrojové kódy

read url and print contents to console

Eric Foster před 6 roky
rodič
revize
75ea06f231
6 změnil soubory, kde provedl 44 přidání a 2 odebrání
  1. 1
    1
      .idea/ZCW-Fido-URLFetch.iml
  2. 1
    1
      .idea/compiler.xml
  3. 1
    0
      .idea/misc.xml
  4. 13
    0
      pom.xml
  5. 28
    0
      src/main/java/Main.java
  6. binární
      target/classes/Main.class

+ 1
- 1
.idea/ZCW-Fido-URLFetch.iml Zobrazit soubor

@@ -1,6 +1,6 @@
1 1
 <?xml version="1.0" encoding="UTF-8"?>
2 2
 <module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
3
-  <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_5">
3
+  <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
4 4
     <output url="file://$MODULE_DIR$/target/classes" />
5 5
     <output-test url="file://$MODULE_DIR$/target/test-classes" />
6 6
     <content url="file://$MODULE_DIR$">

+ 1
- 1
.idea/compiler.xml Zobrazit soubor

@@ -10,7 +10,7 @@
10 10
       </profile>
11 11
     </annotationProcessing>
12 12
     <bytecodeTargetLevel>
13
-      <module name="ZCW-Fido-URLFetch" target="1.5" />
13
+      <module name="ZCW-Fido-URLFetch" target="1.8" />
14 14
     </bytecodeTargetLevel>
15 15
   </component>
16 16
 </project>

+ 1
- 0
.idea/misc.xml Zobrazit soubor

@@ -7,4 +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 11
 </project>

+ 13
- 0
pom.xml Zobrazit soubor

@@ -8,5 +8,18 @@
8 8
     <artifactId>ZCW-Fido-URLFetch</artifactId>
9 9
     <version>1.0-SNAPSHOT</version>
10 10
 
11
+    <build>
12
+        <plugins>
13
+            <plugin>
14
+                <groupId>org.apache.maven.plugins</groupId>
15
+                <artifactId>maven-compiler-plugin</artifactId>
16
+                <configuration>
17
+                    <source>1.8</source>
18
+                    <target>1.8</target>
19
+                </configuration>
20
+            </plugin>
21
+        </plugins>
22
+    </build>
23
+
11 24
     
12 25
 </project>

+ 28
- 0
src/main/java/Main.java Zobrazit soubor

@@ -0,0 +1,28 @@
1
+import java.io.BufferedReader;
2
+import java.io.IOException;
3
+import java.io.InputStreamReader;
4
+import java.net.MalformedURLException;
5
+import java.net.URL;
6
+import java.net.URLConnection;
7
+import java.util.Scanner;
8
+
9
+public class Main {
10
+    public static void main(String[] args) throws IOException {
11
+        Scanner scanner = new Scanner(System.in);
12
+        //ask for a URL
13
+        System.out.println("Enter a url: ");
14
+        String urlInput = scanner.nextLine();
15
+        //fetch the url
16
+        URL url = new URL(urlInput);
17
+        URLConnection urlConnection = url.openConnection();
18
+        BufferedReader br = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
19
+        //print the url
20
+        StringBuilder sb = new StringBuilder();
21
+        String line;
22
+        while ((line = br.readLine()) != null){
23
+            sb.append(line + "\n");
24
+        }
25
+        br.close();
26
+        System.out.println(sb.toString());
27
+    }
28
+}

binární
target/classes/Main.class Zobrazit soubor