URL u = new URL("http://yahoo.cn/?source=yahoo_hp_bt&pid=yhp");
        URLConnection conn = u.openConnection();
        conn.setDoInput(true); 
            BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream())); 
            String line = null; 
            while ((line = in.readLine()) != null) { 
                System.out.println(new String(line.getBytes(),"UTF-8")); 
            } 
            in.close();说明:现在读出来的源代码都能显示正常了,但有个地方却乱码在标题那,各位高手试试<title>360??雅虎全能??/title>

解决方案 »

  1.   

     utf8_value =zhaoshengVO.getT_zsContent();//从HTTP流中取"NAME"的UTF8数据
       try {
        content=new String(utf8_value.getBytes("ISO-8859-1"), "GB2312");
        System.out.println(content);
        content=new String(utf8_value.getBytes(),"ISO8859-1");
        System.out.println(content);
        content=new String(utf8_value.getBytes("ISO-8859-1"), "GBK");
        System.out.println(content);
        content=new String(utf8_value.getBytes("UTF-8"), "GBK");
        System.out.println(content);
        content=new String(utf8_value.getBytes(),"UTF-8");
        System.out.println(content);
       } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
       } 
    自己一个个去试下吧```
      

  2.   


    BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream(),"UTF-8")); 

    System.out.println(new String(line.getBytes("UTF-8"),"UTF-8"));  
    这样改就对了,从输入流读入的时候要指定编码方式