我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();
}
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();
}
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"));
}
我之前就碰到过,如果不转换的话都是???的!
呵呵!