Converting UTF-8 to ISO-8859-1 in Java - how to keep it as single byte
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: 回答1: If you're dealing with character encodings other than UTF-16, you shouldn't be using java.lang.String or the char primitive -- you should only be using byte[] arrays or ByteBuffer objects. Then, you can use java.nio.charset.Charset to convert between encodings: Charset utf8charset = Charset . forName ( "UTF-8" ); Charset iso88591charset = Charset . forName ( "ISO-8859-1" ); ByteBuffer inputBuffer = ByteBuffer . wrap ( new byte []{( byte ) 0xC3 , ( byte ) 0xA2 }); // decode UTF-8 CharBuffer data = utf8charset . decode (