Here you can find the source of convertToChars(final byte[] bytes, final Charset charset)
public static char[] convertToChars(final byte[] bytes, final Charset charset)
//package com.java2s; //License from project: Open Source License import java.nio.ByteBuffer; import java.nio.CharBuffer; import java.nio.charset.Charset; public class Main { public static char[] convertToChars(final byte[] bytes, final Charset charset) { ByteBuffer bb = ByteBuffer.allocate(bytes.length); bb.put(bytes);/*w w w.ja va 2 s .c o m*/ bb.flip(); CharBuffer cb = charset.decode(bb); return cb.array(); } public static char[] convertToChars(final byte[] bytes, final String charsetName) { return convertToChars(bytes, Charset.forName(charsetName)); } public static char[] convertToChars(final byte[] bytes) { return convertToChars(bytes, Charset.defaultCharset()); } public static char[] convertToChars(final String str) { return str.toCharArray(); } }