str1:A B C D E F G
str2:a b c d e f g
str3:A a B b C c D d E e F f G g
主程序中:write(str1,path3);//str1写入是正常的,其它的不正常
private static void write(String str3, String path3) {
try{
File file=new File(path3);
BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file)));
bw.write(str3);
bw.close();
}catch(Exception e){
e.printStackTrace();
}
}
出现乱码通常是字符集的问题:要么是程序输出时就乱码了,要么是查看工具的问题。
我一般用Editplus查看文本文件,打开时可以选择用哪个字符集(Encoding)打开。
若确认程序输出时就乱码,可按如下方式:
java.io.PrintStream ps = null;