一部の文字は特定の文字セットでサポートされていないため、以下のテストは失敗します。サポートされていない文字のみをエンコードするために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);
}