byte数组转为字符串
//指定长度100
private byte[] bytes = new byte[100];
//此处省略获取数据 byte[]中的数据实际长度为30 剩余的70将会自动填充0
//直接转为String
String str = new String(bytes);
//str中前30位为正常字符 后70位为填充 直接页面展示会乱码
System.out.print(str);
//通过下面的方法去掉自动填充的0
String str1 = StringUtils.byteToStr(bytes);
System.out.print(str1); //正确数据 只有实际的30位 没有填充的乱码
/**
* 去掉byte[]中填充的0 转为String
* @param buffer
* @return
*/
public static String byteToStr(byte[] buffer) {
try {
int length = 0;
for (int i = 0; i < buffer.length; ++i) {
if (buffer[i] == 0) {
length = i;
break;
}
}
return new String(buffer, 0, length, "UTF-8");
} catch (Exception e) {
return "";
}
}
原文链接:https://blog.csdn.net/liu9123949/article/details/108795979
--------------------------------
打印一下执行时长
long start=System.currentTimeMillis();
int result = getReceiveNum(psReceiveCoinNum, tdevReturn);
log.debug("getReceiveNum-consume: {}", (System.currentTimeMillis()-start)+"ms");
记录到日志后,用glogg打开文件,过滤 "getReceiveNum-consume“ 即可搜索出需要的行