我需要将 ByteArrayOutputStream
转换为 String
但我无法弄清楚编码。请帮忙 ?我尝试使用 ICUJ 库,但它仅适用于输入流。从字节数组到输入流的转换也可以。
这是我使用默认编码得到的示例。显然新行不应该在那里。
<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n
<html>
\n
<head>
\n
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
\n
<style type=\"text/css\">\n .style_0 { font-family: sans-serif; font-style: normal; font-variant: normal; font-weight: normal; font-size: 10pt; color: black; text-indent: 0em; letter-spacing: normal; word-spacing: normal; text-transform: none; white-space: normal; line-height: normal;}\n .style_1 { height: 5.062in; width: 8.01in;}\n </style>
\n <script type=\"text/javascript\">\n //<![CDATA[\n function redirect(target, url){\n if (target =='_blank'){\n open(url);\n }\n else if (target == '_top'){\n window.top.location.href=url;\n }\n else if (target == '_parent'){\n location.href=url;\n }\n else if (target == '_self'){\n location.href =url;\n }\n else{\n open(url);\n }\n }\n //]]>\n </script>\n
</head>
\n <body class=\"style_0\" style=\" margin:0px;\">\n <table cellpadding=\"0\" style=\"empty-cells: show; border-collapse:collapse; width:8in; overflow: hidden; table-layout:fixed;\">\n
<col>
</col>\n
<tr>
\n
<td></td>
\n
</tr>
\n
<tr>
\n
<td valign=\"top\"></td>
\n
</tr>
\n
<tr>
\n
<td>
\n
<div style=\"overflow:hidden; height:0.5in\">\n <div style=\" overflow:hidden;\">Dec 23, 2013, 7:11 PM</div>
\n </div>\n
</td>
\n
</tr>
\n </table>\n
<hr style=\"color:red\"/>
\n
<div style=\"color:red\">
\n
<div>The following items have errors:\n </div>
\n <br>\n
<div>
\n
<div id=\"error_title\" style=\"text-decoration:underline\">
Chart (id = 12):
\n
最佳答案
I tried Using ICUJ library but It only works for input stream.
您可以从 ByteArrayOutputStream
获取字节数组,然后将其包装在 ByteArrayInputStream
中...并将该传递给 ICUJ方法。
(请记住,ICUJ 可能会直觉到错误的编码。或者这些字节可能不代表任何已知编码中的文本。)
关于java - 如何确定 ByteArrayOutputStream 的编码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20744459/