泰文字符的字符编码

问题描述 投票:0回答:2

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

encoding internationalization rtf
2个回答
0
投票

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

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

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


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()));
© www.soinside.com 2019 - 2024. All rights reserved.