通过编码获取页面
/* from n o w j a v a . c o m */ //package com.nowjava; import java.io.*; import java.net.*; public class Main { public static String getPage(String url, String encoding) throws IOException { return (getPage(url, encoding, null)); } public static String getPage(String url, String encoding, String cookies) throws IOException { URL u = new URL(url); /** 来自 nowjava**/ HttpURLConnection conn = (HttpURLConnection) u.openConnection(); if (cookies != null) conn.setRequestProperty("Cookie", cookies); if (conn.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) return (null); BufferedReader stream = new BufferedReader(new InputStreamReader( conn.getInputStream(), encoding));