Here you can find the source of convertCharset(byte[] content, Charset fromCharset, Charset toCharset)
public static byte[] convertCharset(byte[] content, Charset fromCharset, Charset toCharset)
//package com.java2s; //License from project: Apache License import java.nio.ByteBuffer; import java.nio.CharBuffer; import java.nio.charset.Charset; import java.util.Arrays; public class Main { public static byte[] convertCharset(byte[] content, Charset fromCharset, Charset toCharset) { if (content == null || content.length == 0) return null; if (fromCharset == null || toCharset == null) { throw new IllegalArgumentException("Charset cannot be null!"); }//from ww w .ja v a 2 s . c o m CharBuffer inputContent = fromCharset.decode(ByteBuffer.wrap(content)); ByteBuffer result = toCharset.encode(inputContent); return Arrays.copyOf(result.array(), result.limit()); } }