将字符串转换为4字节数组

时间:2013-10-01 08:49:28

标签: java

有可能吗?

我正在尝试将字符串转换为4字节数组。

我看到了一种使用整数的方法:

int i =55555;
ByteBuffer.allocate(4).putInt(i).array();

找不到使用String的方法。

1 个答案:

答案 0 :(得分:4)

"5555".getBytes();

错误

或者如果您只想要前4个字节

"5555555".substring(0, 4).getBytes();