在做crc校验的过程中遇到了iobuffer转换成string的问题,自己找了点资料写了个简单的方法。
Java代码
1. package
2.
3. import
4. import
5.
6. import
7.
8. /**
9. * iobuffer 转换成String
10. * @Description:TODO
11. * @Date:2012-3-15
12. * @author
13. */
14. public class
15.
16. public static
17. "message = "
18. //调换buffer当前位置,并将当前位置设置成0
19. byte[] b = new byte[iobuffer.limit()];
20. iobuffer.get(b);
21. //此处用stringbuffer是因为 String类是字符串常量,是不可更改的常量。而StringBuffer是字符串变量,它的对象是可以扩充和修改的。
22. new
23.
24. for(int i = 0; i < b.length; i++){
25. "===="
26. //可以根据需要自己改变类型
27. "---------"
28. }
29. return
30. }
31.
32. /**
33. * @param args
34. * @param:@param args
35. * @return:void
36. * @author
37. * @throws CharacterCodingException
38. * @Date:2012-3-15
39. */
40. public static void main(String[] args) throws
41. 8);
42. iobuffer.order(ByteOrder.LITTLE_ENDIAN);
43. 'z');
44. 123);
45.
46. String str = ioBufferToString(iobuffer);
47. System.out.println(str);
48.
49. }
50.
51. }
52.
53.
54. /**
55. * @author create on 2012-3-15
56. */