某些字符集不支持某些字符,因此以下测试失败。我想使用 html 实体只编码那些不支持的字符。怎么样,在java中?
public void testWriter() throws IOException{
String c = "\u00A9";
String encoding = "gb2312";
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
Writer writer = new BufferedWriter(new OutputStreamWriter(outStream, encoding));
writer.write(c);
writer.close();
String result = new String(outStream.toByteArray(), encoding);
assertEquals(c, result);
}