public static String byte2Unicode(byte by[]) {

来源:互联网 发布:炉石淘宝友谊赛封号 编辑:程序博客网 时间:2024/05/02 00:00

public static String byte2Unicode(byte by[]) {
  return byte2Unicode(by, 0, by.length);
 }

 public static String byte2Unicode(byte[] src, int start, int len) {
  if (start + len > src.length || len % 2 != 0) {
   throw new IllegalArgumentException();
  }
  StringBuffer sb = new StringBuffer();
  char ch;
  int i;
  for (i = start; i < start + (len / 2); i++) {
   ch = (char) ((src[start + (i - start) * 2] << 8) | (src[start
     + (i - start) * 2 + 1] & 0xff));
   sb.append(ch);
  }
  return sb.toString();
 }

原创粉丝点击