用JAVA把文件中的ASCII码转成相应字符,在线等,急急急!

文件中的内容是ASCII码,比如313233,程序读取这个文件后,翻译成123,写入另一个文件,注意文件在读取源文件的时候会把本身就是ASCII码的313233再读成333133323333,该怎么办,请高手指点!

每次取两位减去30保存就可以了
333133323333=>33-30,31-30,33-30,32-30,33-30,33-30=>313233;
313233=>31-30,32-30,33-30=>123;

附代码:
String a="333133323333";
String result="";
for(int i=0;i<2;i++){
for(int j=2;j<a.length()+2;j=j+2){
result+=(Integer.parseInt(a.substring(j-2,j))-30)+"";
}
a=result;
result="";
}

System.out.println(a);//a="123"
温馨提示:答案为网友推荐,仅供参考
第1个回答  2009-02-19
这个也是我从网上找的一种解决方案,看上去这个ascii怎么分开挺重要,应该是每五个分一下。
public static void main(String[] args) {
// TODO Auto-generated method stub
String asc = "22307 35806 24555 20048";
String[] chars = asc.split(" ");
for (int i = 0; i < chars.length; i++) {
System.out.println(chars[i] + " "
+ (char) Integer.parseInt(chars[i]));
}

}
希望对你有帮助。
我再提供一下五个一分的方法。
public static void main(String[] args) {
// TODO Auto-generated method stub
String asc = "22307358062455520048";

Matcher m = Pattern.compile("\\d{5}").matcher(asc);
while (m.find()) {
System.out.println(m.group() + (char) Integer.parseInt(m.group()));
}
}
不知道是不是你想要的。
相似回答