日期:2014-05-20 浏览次数:20728 次
URL url = new URL(baseUrl); BufferedReader buff = new BufferedReader(new InputStreamReader(url.openStream()), charSet); StringBuilder sb = new StringBuilder(); String s; while((s = buff.readLine()) != null){ sb.append(s); } return sb.toString();
URL url = new URL("http://www.baidu.com"); BufferedReader buff = new BufferedReader(new InputStreamReader(url.openStream())); StringBuilder sb = new StringBuilder(); String s = null; while((s = buff.readLine()) != null){ sb.append(s+"\n"); } System.out.println(sb);
------解决方案--------------------
应该用:
URLConnection cn = url.openConnection();
然后在从头信息中获取其字符集设置:
cn.getContentEncoding();
------解决方案--------------------