byte数组转换成long
public long byteArrayToLong(byte[] data) throws IOException {
ByteArrayInputStream bai = new ByteArrayInputStream(data);
DataInputStream dis =new DataInputStream(bai);
return dis.readLong();
}

byte数组转换成int
public int byteArrayToInt(byte[] data) throws IOException {
ByteArrayInputStream bai = new ByteArrayInputStream(data);
DataInputStream dis =new DataInputStream(bai);
return dis.readInt();
}

long转换成byte数组
public byte[] longToByteArray(long l) throws IOException {
ByteArrayOutputStream bao = new ByteArrayOutputStream();
DataOutputStream dos =new DataOutputStream(bao);
dos.writeLong(l);
byte [] buf =bao.toByteArray();
return buf;
}

int转换成byte数组
public byte[] intToByteArray(int a) throws IOException {
ByteArrayOutputStream bao = new ByteArrayOutputStream();
DataOutputStream dos =new DataOutputStream(bao);
dos.writeInt(a);
byte [] buf =bao.toByteArray();
return buf;
}

 

 

相关文章:

  • 2022-02-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-06
  • 2021-12-24
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-27
  • 2022-12-23
  • 2021-08-06
相关资源
相似解决方案