Skip to content

Instantly share code, notes, and snippets.

@alexzhan
Created October 8, 2010 15:13
Show Gist options
  • Save alexzhan/616944 to your computer and use it in GitHub Desktop.
Save alexzhan/616944 to your computer and use it in GitHub Desktop.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.Date;
public class YangInitial {
private static String getDocumentAt(String urlString) {
StringBuffer html_text = new StringBuffer();
try {
URL url = new URL(urlString);
URLConnection conn = url.openConnection();
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream(),"utf8"));
String line = null;
while ((line = reader.readLine()) != null){
html_text.append(line + "\n");
}
reader.close();
}catch (MalformedURLException e) {
System.out.println("invalid URL: " + urlString);
} catch (IOException e) {
e.printStackTrace();
}
return html_text.toString();
}
public static void main(String[] args) {
String string = null;
String url = "http://t.sina.com.cn/alexzhan";
Date time1=new Date();
string = getDocumentAt(url);
System.err.println(string);
Date time2 = new Date();
long processtime=time2.getTime()-time1.getTime();
System.out.println("Done with time("+processtime+"ms");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment