如何将jpcap 中byte[] 类型的packet.data 转换成String,而不出现乱码
展开全部
调用BytesToHexString(packet.data)函数,有效解决你所说的问题
例如:
String PacketHexString = BytesToHexString(packet.data);
public String BytesToHexString(byte[] b)
{
String hs = "";
String stmp = "";
for(int n = 0;n < b.length;n++)
{
stmp = (Integer.toHexString(b[n] & 0XFF));
if(stmp.length() == 1)
hs = hs + "0" + stmp;
else
hs = hs + stmp;
}
return hs.toUpperCase();
}
例如:
String PacketHexString = BytesToHexString(packet.data);
public String BytesToHexString(byte[] b)
{
String hs = "";
String stmp = "";
for(int n = 0;n < b.length;n++)
{
stmp = (Integer.toHexString(b[n] & 0XFF));
if(stmp.length() == 1)
hs = hs + "0" + stmp;
else
hs = hs + stmp;
}
return hs.toUpperCase();
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询