JAVA(6)-Bytebuf-」string 字符转换

//1.String ->Bytebuf
//把string text转换成Bytebuf
channel.writeAndFlush(Unpooled.copiedBuffer(text.getBytes());


//2.Object msg->String str
//readableBytes()长度,readIndex()起始位置
ByteBuf buf=null;
buf =(ByteBuf)msg;
byte[] bytes=new byte[buf.readableBytes()];//
buf.getBytes(buf.readIndex(),bytes);
String str=new String(bytes);

 

posted @ 2020-07-06 20:58  jasmineTang  阅读(856)  评论(0)    收藏  举报