JAVA通过url获取页面内容

        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();

 

posted @ 2015-05-05 08:43  rubekid  阅读(1451)  评论(0编辑  收藏  举报