Last active
February 8, 2020 02:18
-
-
Save ryu1kn/a08b367239da2b445b85020ef2598bfe to your computer and use it in GitHub Desktop.
Page get with no external dependencies
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
import java.net.URL; | |
import java.util.Scanner; | |
class GetPage { | |
public static void main(String[] args) throws IOException { | |
String endpoint = System.getProperty("endpoint"); | |
if (endpoint == null) printUsage(); | |
else printPage(endpoint); | |
} | |
private static void printUsage() { | |
System.out.println("\n Usage:\n\n $ java -Dendpoint=https://www.google.com GetPage"); | |
} | |
private static void printPage(String endpoint) throws IOException { | |
InputStream response = new URL(endpoint).openStream(); | |
try (Scanner scanner = new Scanner(response)) { | |
while (scanner.hasNext()) System.out.println(scanner.next()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment