Skip to content

Instantly share code, notes, and snippets.

@FreeFly19
Created January 31, 2017 22:53
Show Gist options
  • Save FreeFly19/9d2bb1828f46e98f13631b68de9544aa to your computer and use it in GitHub Desktop.
Save FreeFly19/9d2bb1828f46e98f13631b68de9544aa to your computer and use it in GitHub Desktop.
Downloading HTML through HTTP (http client example)
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws Exception {
URL url = new URL("http://example.com");
URLConnection urlConnection = url.openConnection();
InputStream inputStream = urlConnection.getInputStream();
Scanner scanner = new Scanner(inputStream);
while(scanner.hasNextLine()) {
System.out.println(scanner.nextLine());
}
inputStream.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment