日期:2014-05-20 浏览次数:20792 次
public String getHtmlCode(String addr) { BufferedReader in = null; URLConnection conn = null; try { URL url = new URL("www.xxx.com"); conn = url.openConnection(); conn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)"); String str; in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8")); StringBuffer sb = new StringBuffer(); while (null != (str = in.readLine())) { sb.append(str + "\n"); } return sb.toString(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { try { if (null != in) in.close(); } catch (IOException e2) { // TODO: handle exception// } } return null; }