Here you can find the source of ByteToString(byte[] a, int nLen)
private static String ByteToString(byte[] a, int nLen)
//package com.java2s; //License from project: Apache License public class Main { private static String ByteToString(byte[] a, int nLen) { int nALen = a.length; if (nLen < 0) { for (int i = (nALen - 1); i > 0; i--) { if (a[i] != 0) { nLen = i + 1;/*from w w w .jav a2 s.co m*/ break; } } } if (nALen < nLen) { nLen = nALen; } if (nLen == 0) { return ""; } else { byte[] bstr = new byte[nLen]; System.arraycopy(a, 0, bstr, 0, nLen); return new String(bstr); } } }