String usernm="useruser";//usernm是个8字节字符串
ByteBuffer btdbuf = ByteBuffer.allocate(dlen);
btdbuf.putInt(0,Integer.parseInt(usernm));
我这么处理运行会出错,怎样才能正确将这个8位的字符串放进btdbuf中呀?
ByteBuffer btdbuf = ByteBuffer.allocate(dlen);
btdbuf.putInt(0,Integer.parseInt(usernm));
我这么处理运行会出错,怎样才能正确将这个8位的字符串放进btdbuf中呀?
short dlen = 35;
byte cmd[] = new byte[2];
//发送登陆信息
String usernm ="useruser";
String pass="12345678";
String ip = "192168123124000";
int port = 3001;
ByteBuffer btdbuf = ByteBuffer.allocate(dlen);
cmd[0] = 'D';
cmd[1] = '1';
btdbuf.putLong(0,Long.parseLong(usernm));log.info("user?");
btdbuf.putLong(8,Long.parseLong(pass));
btdbuf.putLong(16,Long.parseLong(ip));
btdbuf.putInt(31,port);
byte buf[] = new byte[dlen];
DataPack.BuftoArr(btdbuf,0,dlen,buf);
ByteBuffer btsbuf = dp.createdp_stoequ((short)0,(byte)0,cmd,dlen,buf);
if(clios !=null) clios.write(btsbuf,null);
}
就是要将一个8位的字符串用ByteBuffer的put方法放进数据缓冲区,需要转型应该用哪种方法才能将这个 8位的字符串完成的放进去?
这条语句没有出错??
我就是问关于usernm应该怎么处理才能完整放进bytebuffer中
为
btdbuf.putLong(0,usernm.getBytes);
试试