[code="java"]
package util;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import sun.net.www.protocol.http.HttpURLConnection;
public class TestURL {
public static void main(String[] args) {
try {
URL url = new URL("http://www.baidu.com");
HttpURLConnection urlc =(HttpURLConnection) url.openConnection();
//urlc.getContent();
urlc.connect();
BufferedReader br = new BufferedReader(new InputStreamReader(urlc.getInputStream(),"UTF-8"));
StringBuffer sb = new StringBuffer();
while (br.readLine() != null) {
sb.append(br.readLine());
}
System.out.println(sb.toString());
br.close();
urlc.disconnect();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
[/code]