Skip to content

Instantly share code, notes, and snippets.

@ryu1kn
Last active February 8, 2020 02:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryu1kn/a08b367239da2b445b85020ef2598bfe to your computer and use it in GitHub Desktop.
Save ryu1kn/a08b367239da2b445b85020ef2598bfe to your computer and use it in GitHub Desktop.
Page get with no external dependencies
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