public static String utf8Byte2String

来源:互联网 发布:js 获取元素父节点 编辑:程序博客网 时间:2024/04/18 22:00

public static String utf8Byte2String(byte[] utf8byte, int fromIndex,
   int size) {
  String s = "";
  ByteArrayInputStream strmBytes = null;
  DataInputStream strmDataType = null;
  ;
  try {

   byte data[] = new byte[size + 2];
   data[0] = (byte) (size >> 8);
   data[1] = (byte) (size);

   System.arraycopy(utf8byte, fromIndex, data, 2, size);

   strmBytes = new ByteArrayInputStream(data);
   strmDataType = new DataInputStream(strmBytes);
   s = strmDataType.readUTF();
  } catch (IOException e) {

  } catch (Exception e) {

  } finally {
   if (strmDataType != null) {
    try {
     strmDataType.close();
    } catch (IOException e) {
    }
   }
   if (strmBytes != null) {
    try {
     strmBytes.close();
    } catch (IOException e) {
    }
   }

  }

  return s;
 }

原创粉丝点击