泰国字符的字符编码

时间:2009-07-30 08:00:44

标签: encoding internationalization rtf

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

谢谢和问候, 拉姆亚。

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

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())); 

2 个答案:

答案 0 :(得分:0)

我不认为记事本会处理所有字符编码,而不是谷歌搜索。您是否可以尝试将字符重新编码为UTF-8(或其他一些unicode格式),因为记事本确实正确处理了这个问题?你want to use the BOM

我还偶然发现了tool for converting files in Thai其他各种编码。

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

答案 1 :(得分: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()));
相关问题