Here you can find the source of bytes2String(byte[] bytes)
public static String bytes2String(byte[] bytes)
//package com.java2s; /**/*w w w .ja v a 2 s. co m*/ * Copyright (c) 2012 Baozun All Rights Reserved. * * This software is the confidential and proprietary information of Baozun. * You shall not disclose such Confidential Information and shall use it only in * accordance with the terms of the license agreement you entered into * with Baozun. * * BAOZUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR * PURPOSE, OR NON-INFRINGEMENT. BAOZUN SHALL NOT BE LIABLE FOR ANY DAMAGES * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING * THIS SOFTWARE OR ITS DERIVATIVES. * */ public class Main { private static final char[] Digit = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; public static String bytes2String(byte[] bytes) { if (bytes == null || bytes.length == 0) return ""; StringBuffer sb = new StringBuffer(); for (byte b : bytes) sb.append(byte2HEX(b)); return sb.toString(); } public static String byte2HEX(byte ib) { char[] ob = new char[2]; ob[0] = Digit[(ib >>> 4) & 0X0F]; ob[1] = Digit[ib & 0X0F]; String s = new String(ob); return s; } }