Here you can find the source of convertToString(byte[] bytes, Charset charset)
public static String convertToString(byte[] bytes, Charset charset)
//package com.java2s; //License from project: Apache License import java.nio.charset.*; public class Main { public static String convertToString(byte[] bytes, Charset charset) { String ret = new String(bytes, charset); if ((bytes[0] == 0xEF - 256) && (bytes[1] == 0xBB - 256) && (bytes[2] == 0xBF - 256)) { ret = ret.substring(1);/*from w ww .j a va 2 s. c o m*/ } else if ((bytes[0] == 0xFE - 256) && (bytes[1] == 0xFF - 256)) { ret = ret.substring(1); } else if ((bytes[0] == 0xFF - 256) && (bytes[1] == 0xFE - 256)) { ret = ret.substring(1); } return ret; } }