java学友们进来帮解一题,字符集问题.

来源:百度知道 编辑:UC知道 时间:2024/06/06 14:21:29
import java.io.*;
import java charcode{
public static void main(String args[]) throws Exception{
System.setProperty("file.encoding","iso8859-1");
System.getProperties().list(System.out);

String strchina="中国";
for(int i=0;i<strchina.length();i++)
System.out.println(Integer.toHexString(strchina.charAt(i)));
byte buf[] ;
buf= strchina.getBytes();
for(int i=0;i<buf.length;i++)
System.out.println(Integer.toHexString(buf[i]));
for(int i=0;i<buf.length;i++)
System.out.write(buf[i]); \\为什么这里输出的是乱码而不是中国呢 ??
System.out.println();

另外给我讲了一下-符集问题,(gb2312是否兼容ask码).
尽量详细一点
如查分不够我可以再加50分.

你定义的buf[i]是byte型 中国是char型 我想问题在这里吧!
也可能是gb2312不兼容国际标准编码
System.setProperty("file.encoding","iso8859-1");
把这里改下