如果你还在利用String类的构造方法来实现编码转换的话
(
例如:
String result = new String(s.getBytes("ISO-8859-1"), "UTF-8");
)
那么我这儿有更高效的一种方法:利用NIO中的Charset转换编码
(
例如:
String result = Charset.forName("UTF-8").decode(ByteBuffer.wrap(s.getBytes("ISO-8859-1"))).toString();
)
参见文档:
public final CharBuffer decode(ByteBuffer bb)
文档说明为:Convenience method that decodes bytes in this charset into Unicode characters.
(
例如:
String result = new String(s.getBytes("ISO-8859-1"), "UTF-8");
)
那么我这儿有更高效的一种方法:利用NIO中的Charset转换编码
(
例如:
String result = Charset.forName("UTF-8").decode(ByteBuffer.wrap(s.getBytes("ISO-8859-1"))).toString();
)
参见文档:
public final CharBuffer decode(ByteBuffer bb)
文档说明为:Convenience method that decodes bytes in this charset into Unicode characters.