我正在尝试使用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>��</p>
</body>
</html>