1

我需要读取带有泰文字符的 RTF 文件并将其写入文本文件。我尝试使用 TIS-620、MS874、ISO-8859-11,但是当我在记事本或文本本中打开生成的输出文件时,泰语字符无法正确显示。但它适用于写字板。请指导我。

4

2 回答 2

0

我不认为记事本处理所有字符编码,来自一点谷歌搜索。您能否尝试将字符重新编码为 UTF-8(或其他一些 unicode 格式),因为记事本确实可以正确处理?您将要使用 BOM

我还偶然发现了一种将泰语文件转换为各种其他编码的工具。

最后,是否要求文件可以在记事本中打开?记事本并不是文本编辑中的最后一个词。

于 2009-07-30T08:30:01.813 回答
0

解决问题的代码(发表在评论中,在此处添加以使其可读!):

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()));
于 2020-11-13T10:07:42.980 回答