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