【发布时间】:2009-07-30 08:00:43
【问题描述】:
我需要读取带有泰文字符的 RTF 文件并将其写入文本文件。我尝试使用 TIS-620、MS874、ISO-8859-11,但是当我在记事本或文本本中打开生成的输出文件时,泰语字符显示不正确。但它适用于写字板。请指导我。
【问题讨论】:
-
没有输出文件是文本文件。我们用下面发布的代码解决了这个问题。
标签: encoding internationalization rtf
我需要读取带有泰文字符的 RTF 文件并将其写入文本文件。我尝试使用 TIS-620、MS874、ISO-8859-11,但是当我在记事本或文本本中打开生成的输出文件时,泰语字符显示不正确。但它适用于写字板。请指导我。
【问题讨论】:
标签: encoding internationalization rtf
我不认为记事本可以处理所有字符编码,来自一点谷歌搜索。您能否尝试将字符重新编码为 UTF-8(或其他一些 unicode 格式),因为记事本确实可以正确处理?你会want to use the BOM。
我还偶然发现了 tool for converting files in Thai 到各种其他编码。
最后,文件是否可以在记事本中打开?记事本并不是文本编辑中的最后一个词。
【讨论】:
解决问题的代码(发表在评论中,在此处添加以使其可读!):
FileInputStream fin = new FileInputStream(fileName);
DataInputStream din = new DataInputStream(fin);
//creating a default blank styled document
DefaultStyledDocument styledDoc = new DefaultStyledDocument();
//Creating a RTF Editor kit
RTFEditorKit rtfKit = new RTFEditorKit();
//Populating the contents in the blank styled document
rtfKit.read(din,styledDoc,0);
// Getting the root document
Document doc = styledDoc.getDefaultRootElement().getDocument();
//Printing out the contents of the RTF document as plain text
System.out.println(doc.getText(0,doc.getLength()));
【讨论】: