日期:2014-05-20 浏览次数:20829 次
import java.io.IOException; import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; import java.net.*; import java.util.regex.Matcher; import java.util.regex.Pattern; public class network { public static String getCharset(BufferedReader in){ Pattern Pname=Pattern.compile("charset=(\\w*)\\p{Punct}*",Pattern.UNIX_LINES); Matcher Mk =null; String name=null; try{ for(int jk=0 ; jk<4 ; jk++){ for(int i=0 ; i<4 ; i++) name=in.readLine(); Mk =Pname.matcher(name); if(Mk.find()) break; } return Mk.group(1) ; }catch(IllegalStateException e){ return null; }catch( IOException e){ return null; }finally{ try { if(in != null) in.close(); } catch (IOException e) { return null; } } } }