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