Created
May 17, 2016 03:51
-
-
Save jose-vm/a2fc801a1d7103db42f2bccac7233d4e to your computer and use it in GitHub Desktop.
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.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