Skip to content

Instantly share code, notes, and snippets.

@tonetheman
Created March 26, 2009 01:33
Show Gist options
  • Save tonetheman/85815 to your computer and use it in GitHub Desktop.
Save tonetheman/85815 to your computer and use it in GitHub Desktop.
urllib for java
import java.net.*;
import java.io.*;
class urllib {
public static StringBuffer urlopen(String url) {
try {
URL u = new URL(url);
StringBuffer sb = new StringBuffer();
BufferedReader in = new BufferedReader(
new InputStreamReader(u.openStream()));
String str = null;
while((str = in.readLine())!=null) {
sb.append(str);
}
in.close();
return sb;
} catch(MalformedURLException e) {
e.printStackTrace();
} catch(IOException e) {
e.printStackTrace();
}
return null;
}
}
public class UT {
public static void main(String[] args) {
StringBuffer sb = urllib.urlopen("http://dailykenken.com");
System.out.println(sb);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment