import java.io.*;
public class TestEncode_1 {
public static void main(String[] args) throws Exception{
// TODO Auto-generated method stub
FileInputStream f1=new FileInputStream("c:/123.txt");
FileWriter fw=new FileWriter("d:/123.txt");
byte[] b=new byte[20];
f1.read(b);
String s=new String(b,"GBK"); //s的内容为 锘縅ava绋嬪簭璁捐鏁欑▼
fw.write(s); //最后d:/123.txt 的内容为 Java程序设计教程
fw.close();
}
}
"c:/123.txt"是一个utf-8编码的文件,而"d:/123.txt"则是一个ANSI编码的文件,得到的s理所当然是乱码啦,
但将乱码s写进 d:/123.txt 里面后就变成原文了,这就不懂了请各位高手帮忙下,小弟在此谢过了
public class TestEncode_1 {
public static void main(String[] args) throws Exception{
// TODO Auto-generated method stub
FileInputStream f1=new FileInputStream("c:/123.txt");
FileWriter fw=new FileWriter("d:/123.txt");
byte[] b=new byte[20];
f1.read(b);
String s=new String(b,"GBK"); //s的内容为 锘縅ava绋嬪簭璁捐鏁欑▼
fw.write(s); //最后d:/123.txt 的内容为 Java程序设计教程
fw.close();
}
}
"c:/123.txt"是一个utf-8编码的文件,而"d:/123.txt"则是一个ANSI编码的文件,得到的s理所当然是乱码啦,
但将乱码s写进 d:/123.txt 里面后就变成原文了,这就不懂了请各位高手帮忙下,小弟在此谢过了
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货