我正在尝试将不同语言的字符串写入rtf文件。我已经尝试了几个不同的东西。 我在这里使用日语作为例子,但对于我尝试过的其他语言也是如此。将unicode写入rtf文件
public void writeToFile(){
String strJapanese = "日本語";
DataOutputStream outStream;
File file = new File("C:\\file.rtf");
try{
outStream = new DataOutputStream(new FileOutputStream(file));
outStream.writeBytes(strJapanese);
outStream.close();
}catch (Exception e){
System.out.println(e.toString());
}
}
我ALSE曾尝试:
byte[] b = strJapanese.getBytes("UTF-8");
String output = new String(b);
或者更具体:
byte[] b = strJapanese.getBytes("Shift-JIS");
String output = new String(b);
输出流也有writeUTF方法:
outStream.writeUTF(strJapanese);
可以使用字节[]直接在输出流中写入方法。除西欧语言外,上述所有内容都给我提供了一些乱码。要查看它是否有效我已经尝试在记事本++中打开结果文档并设置适当的编码。此外,我使用OpenOffice,您可以在打开文档时选择编码和字体。
如果它能工作,但我的电脑无法正常打开,有没有办法检查?
作品,我用“Shift-JIS”代替“UTF-8”进行编码。谢谢。 – Oglop