给你一个函数。需要j2sdk1.4 中的 java.nio.*
如果一定好j2sdk1.3,也可以用流代替ByteBuffer public static void int2bytes(int in, byte[] dst, int offset) {
ByteBuffer bb = ByteBuffer.allocate(4);
bb.clear();
bb.putShort(in);
bb.flip();
bb.get(dst, offset, 4);
}
如果一定好j2sdk1.3,也可以用流代替ByteBuffer public static void int2bytes(int in, byte[] dst, int offset) {
ByteBuffer bb = ByteBuffer.allocate(4);
bb.clear();
bb.putShort(in);
bb.flip();
bb.get(dst, offset, 4);
}
解决方案 »
- [求助]使用org.w3c.dom写入XML文件问题!
- 如何把数据库的数据写入jtable
- JTable的排序问题! 点击table各个列头, 然后table中的数据就会按所点列排序 (用jdk1.5)
- 颜色选择对话框的多国语言化
- 关于java解析wml,xml问题
- 谁有自定义table源代码
- 书上说:Class.forName()可以使用这个方法检测一个对象是否是一个特定类的对象,我不懂这个意思?
- 求助:FileFilter类的问题,解决
- 关于Applet在网页中显示的问题
- 如何初始化一个自建类型的数组 ??
- 在哪有IBM VisualAge for Java的帮助文档?最好是中文的?
- 如何得到UTC时间?
bb.putShort(in);
应该是bb.putInt(in);
{
byte[] byteValue = new byte[4];
int shift = 0;
for (int x = 0; x < 4; x++)
{
shift -= 8;
byteValue[x] = (byte)(intValue >>> shift);
}
return byteValue;
}
{
int intValue = 0;
//如果byte数组长度不足4位,则抛出异常
if (byteValues.length <4 )
{
throw new Exception("传入的byte数组不足4位");
}
//只取Bytes的前4位
for (int x = 0; x < 4; x++)
{
intValue <<= 8;
intValue |= byteValues[x] & 0xFF;
}
return intValue;
}