JAVA通过url获取页面内容

时间:2024-11-28 21:37:53
        String address = "http://sports.sina.com.cn/nba/live.html?id=2015050405";
URL url = new URL(address);
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
InputStreamReader input = new InputStreamReader(connection.getInputStream(), "utf-8");
BufferedReader reader = new BufferedReader(input);
String line = "";
StringBuffer stringBuffer = new StringBuffer();
while((line = reader.readLine()) != null){
stringBuffer.append(line);
} String string = stringBuffer.toString();