Skip to content

Instantly share code, notes, and snippets.

@bfritz
Created February 10, 2015 02:01
Show Gist options
  • Select an option

  • Save bfritz/cb9037e7e7321f899168 to your computer and use it in GitHub Desktop.

Select an option

Save bfritz/cb9037e7e7321f899168 to your computer and use it in GitHub Desktop.
Java class to cat a URL to System.out (not production code)
import java.io.InputStream;
import java.net.*;
public class UrlFetch {
public static void main(String... args) throws Exception {
URL url = new URL(args[0]);
URLConnection conn = url.openConnection();
InputStream is = conn.getInputStream();
while (is.available() > 0) {
System.out.print((char) is.read());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment