【问题标题】:Character encoding for thai characters泰文字符的字符编码
【发布时间】:2009-07-30 08:00:43
【问题描述】:

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

【问题讨论】:

  • 没有输出文件是文本文件。我们用下面发布的代码解决了这个问题。

标签: encoding internationalization rtf


【解决方案1】:

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

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

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

【讨论】:

  • FileInputStream fin = new FileInputStream(fileName); DataInputStream din = new DataInputStream(fin); //创建一个默认的空白样式文档 DefaultStyledDocument styledDoc = new DefaultStyledDocument(); //创建一个 RTF 编辑器套件 RTFEditorKit rtfKit = new RTFEditorKit(); //填充空白样式文档中的内容 rtfKit.read(din,styledDoc,0); // 获取根文档 Document doc = styledDoc.getDefaultRootElement().getDocument(); //将RTF文档的内容打印为纯文本 System.out.println(doc.getText(0,doc.getLength()));
  • 这是如何解决问题的?这对文件输出流的编码根本没有任何作用!
【解决方案2】:

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

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

【讨论】:

    猜你喜欢
    • 2012-08-26
    • 2016-02-09
    • 2014-12-21
    • 1970-01-01
    • 1970-01-01
    • 2019-07-14
    • 1970-01-01
    • 2013-12-29
    相关资源
    最近更新 更多