import org.apache.commons.io.IOUtils;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
public class URLConnectionDemo {
public static void main(String[] args) throws Exception {
URL url = new URL("http://www.baidu.com"); //制定操作的URL
URLConnection urlConnection = url.openConnection(); //建立连接
System.out.println(IOUtils.toString((InputStream) urlConnection.getContent(), "utf-8")); //取得内容
System.out.println(urlConnection.getContentLength()); //取得内容大小
System.out.println(urlConnection.getContentType()); //取得内容类型
}
}