JAVA中将字节流转换成字符串

public static final String BufferToHexStr(byte[] data, int off, int length)
{
//格式: 0D ab 09 bc
StringBuffer buf = new StringBuffer(data.length * 2);
int tempData = 0;
for (int i = off; i < length; i++)
{
tempData = (int)data[i] & 0xff;
if (tempData < 0x10)
{
buf.append("0");
}
buf.append(Long.toString(tempData, 16));
if (i < data.length - 1)
{
buf.append(" ");
}
}
return buf.toString();
}

猜你喜欢

转载自wxhlove.iteye.com/blog/1837012