我URL类提取一个msn spaces的内容时所有的中文都是乱码,不知道为什么,请高手指点。
public class Connection
{
    public static void main(String args[]) throws Exception
    {
  
        URL url=new URL("http://xxx.spaces.live.com");

Scanner s=new Scanner(url.openStream()); while(s.hasNextLine())
{
System.out.println(s.nextLine());
}
s.close();


    }

解决方案 »

  1.   

    先用getBytes得到原始字节流后,然后使用String的构造方法,指定编码显示出来就可以解决乱码问题了~~
      

  2.   

    可能是 UTF-8 的格式而楼主没有转换过来。
      

  3.   

    re:ferreousbox:试了一下,还是不行……UTF-8格式应如何作转换?
      

  4.   

    兄弟啊,你一定没有进行编码转换吧!
    if(编码是UTF-8){
    str = new String(str.getBytes("ISO-8859-1"),"UTF-8");
    }else if(GBK){
    str = new String(str.getBytes("ISO-8859-1"),"GBK");
    }else{
    str = new String(str.getBytes("ISO-8859-1"));
    }
    我之前就碰到过,如果不转换的话都是???的!
    呵呵!
      

  5.   

    你取到的应该时字节流,需要经过编码  str = new String(str.getBytes("ISO-8859-1"),"GBK");