我目前正在对 Shift-JIS 格式的输出 CSV 文件进行一些测试,但不知何故,我发现在不同日文字符的试验中很奇怪,如下所示:
我的代码:
try {
String dat2 = "カヨ ハラダ";
String dat = "2バイト文字出力";
String fileName = "C:/Users/CR/Desktop/test2.txt";
FileOutputStream fos = new FileOutputStream(fileName);
OutputStreamWriter osw = new OutputStreamWriter(fos, "Shift_JIS");
BufferedWriter fp = new BufferedWriter(osw);
fp.write(new String(dat2.getBytes("Shift_JIS"));
fp.newLine();
fp.flush();
fp.close();
fos.close();
} catch (Exception ex) {
throw new Exception(ex);
}
dat2 的结果:
它不是 Shift-JIS 格式,并且单词也不正确,因此再次试用:
dat 的结果:
这也可以以预期的格式正确显示。
有什么事吗?还是内容不正确?
谢谢 !