使用Java HtmlEditorKit保存汉字

时间:2018-10-02 15:18:07

标签: java chinese-locale htmleditorkit

我正在尝试使用HtmlEditorKit以以下方式保存包含汉字的HtmlDocument(使用UTF-8编码保存)

try (OutputStreamWriter f = new OutputStreamWriter(fileOutputStream, "UTF-8")) {
    htmlEditorKit.write(f, htmlDocument, 0, htmlDocument.getLength());
} catch (BadLocationException e) {
    logger.error("Could not save", e);
}

在输出HTML文档中,我得到了两个2个字节的字符(amp#55361; amp#57102;),而不是一个4个字节的字符。 Java可以通过将两者结合在一起来理解它是哪个符号,但是HTML不能。
关于如何保存它的任何建议,以便可以正确显示HTML页面?

此处输出html:

<html>
<head>
<meta content="text/html" charset="utf-8">
</head>
<body>
<p>&#55361;&#57102;</p>
</body>
</html>

0 个答案:

没有答案