解编码问题,请教,大家帮忙。

J_NeedForSpeed 2006-12-06 07:09:11
import java.io.*;
public class test
{
public static void main(String [] args) throws Exception
{
System.getProperties().put("file.encoding","iso8859-1");
System.out.println("please enter a Chinese String");
byte [] buf=new byte[1024];
int ch=0;
int pos=0;
String strInfo=null;
while(true)
{
ch =System.in.read();
System.out.println("ghy:"+Integer.toHexString(ch));
switch(ch)
{
case '\r':
break;
case '\n':
strInfo= new String(buf,0,pos,"iso8859-1");
//上面我已经使用iso8859-1码了,应该在下面的
//循环语句中打印不是
//d6
//d0
//b9
//fa
//啊?为什么打印出正确的呢?
for(int i=0;i<strInfo.length();i++)
{
System.out.println(Integer.toHexString
((int)strInfo.charAt(i)));
}
System.out.println(strInfo);
for(int i=0;i<pos;i++)
System.out.write(buf[i]);
System.out.println();
return;
default:
buf[pos++]=(byte)ch;
}
}
}
}
...全文
102 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧