nafis nibir 6 years ago
parent
commit
2092bf9d23

+ 2
- 0
.idea/ZCW-Fido-URLFetch.iml View File

@@ -11,5 +11,7 @@
11 11
     </content>
12 12
     <orderEntry type="inheritedJdk" />
13 13
     <orderEntry type="sourceFolder" forTests="false" />
14
+    <orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
15
+    <orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
14 16
   </component>
15 17
 </module>

+ 9
- 1
pom.xml View File

@@ -19,5 +19,13 @@
19 19
             </plugin>
20 20
         </plugins>
21 21
     </build>
22
-    
22
+    <dependencies>
23
+        <dependency>
24
+            <groupId>junit</groupId>
25
+            <artifactId>junit</artifactId>
26
+            <version>RELEASE</version>
27
+            <scope>test</scope>
28
+        </dependency>
29
+    </dependencies>
30
+
23 31
 </project>

+ 28
- 2
src/main/java/Main.java View File

@@ -1,7 +1,33 @@
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.sql.SQLOutput;
8
+import java.util.Scanner;
9
+
1 10
 public class Main {
2
-    public static void main(String[] args) {
11
+    public static void main(String[] args) throws IOException {
12
+
3 13
         //ask for a url
14
+        Scanner input = new Scanner(System.in);
15
+        System.out.println("Enter a URL without the http:// part but including the dot whatever part");
16
+        URL url= new URL("https://" + input.nextLine());
17
+
4 18
         // fetch the url
19
+        URLConnection yc = url.openConnection();
20
+        BufferedReader in = new BufferedReader(new InputStreamReader(
21
+                yc.getInputStream()));
22
+        String inputLine;
23
+
5 24
         // print the url
25
+        while ((inputLine = in.readLine()) != null)
26
+            System.out.println(inputLine);
27
+        in.close();
28
+
29
+        }
30
+
6 31
     }
7
-}
32
+
33
+

+ 9
- 0
src/test/java/MainTest.java View File

@@ -0,0 +1,9 @@
1
+import org.junit.Test;
2
+
3
+import static org.junit.Assert.*;
4
+
5
+public class MainTest {
6
+
7
+
8
+
9
+}

BIN
target/classes/Main.class View File


BIN
target/test-classes/MainTest.class View File