请教一下,下面这段程序在命令行输入“园:”这样一个汉字和一个半角冒号为什么显示的时候是乱码呢?我是用eclipse的命令行输入的public class Test {
public static void main(String[] args) throws UnsupportedEncodingException,
IOException {
String msg = null;
byte[] ind = new byte[1024];
int readNum = 0;
while ((readNum = System.in.read(ind)) != -1) {
msg = new String(ind, 0, readNum, "UTF-8");
break;
}
System.out.println("==========>" + msg);
for (byte b : msg.getBytes()) {
System.out.print(b + " ");
}
System.out.println();
for (byte b : "园:".getBytes()) {
System.out.print(b + " ");
}
}
}
public static void main(String[] args) throws UnsupportedEncodingException,
IOException {
String msg = null;
byte[] ind = new byte[1024];
int readNum = 0;
while ((readNum = System.in.read(ind)) != -1) {
msg = new String(ind, 0, readNum, "UTF-8");
break;
}
System.out.println("==========>" + msg);
for (byte b : msg.getBytes()) {
System.out.print(b + " ");
}
System.out.println();
for (byte b : "园:".getBytes()) {
System.out.print(b + " ");
}
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货