Skip to content

Instantly share code, notes, and snippets.

@jose-vm
Created May 17, 2016 03:51
Show Gist options
  • Save jose-vm/a2fc801a1d7103db42f2bccac7233d4e to your computer and use it in GitHub Desktop.
Save jose-vm/a2fc801a1d7103db42f2bccac7233d4e to your computer and use it in GitHub Desktop.
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
public static String getContents(String url, String encodeType) {
URL u;
StringBuilder builder = new StringBuilder();
try {
u = new URL(url);
try {
BufferedReader theHTML = new BufferedReader(new InputStreamReader(u.openStream(), encodeType));
String thisLine;
while ((thisLine = theHTML.readLine()) != null) {
builder.append(thisLine).append("\n");
}
}
catch (Exception e) {
System.err.println(e);
}
} catch (MalformedURLException e) {
System.err.println(url + " is not a parseable URL");
System.err.println(e);
}
return builder.toString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment