Here you can find the source of toChars(byte[] b, String charset)
public static char[] toChars(byte[] b, String charset)
//package com.java2s; /* Copyright (c) 2001 - 2013 OpenPlans - www.openplans.org. All rights reserved. * This code is licensed under the GPL 2.0 license, available at the root * application directory.//ww w .ja va2 s . co m */ import java.nio.ByteBuffer; import java.nio.CharBuffer; import java.nio.charset.Charset; public class Main { /** * Converts byte array to char array. * <p> * This method is unsafe since the charset is not specified, one of * {@link #toChars(byte[], String)} or {@link #toChars(byte[], Charset)} should be used * instead. When not specified {@link Charset#defaultCharset()} is used. * </p> */ public static char[] toChars(byte[] b) { return toChars(b, Charset.defaultCharset()); } /** * Converts byte array to char array. */ public static char[] toChars(byte[] b, String charset) { return toChars(b, Charset.forName(charset)); } /** * Converts byte array to char array. */ public static char[] toChars(byte[] b, Charset charset) { CharBuffer buff = charset.decode(ByteBuffer.wrap(b)); char[] tmp = new char[buff.limit()]; buff.get(tmp); return tmp; } }