JAVA ASCII码 读入字符串测试
public class RhzfYunTest {
public static void main(String[] args) { int lenSize =6; byte[] line = (byte[])null; byte[] lenBuffer = new byte[lenSize]; String readLine = null;
int messageLength; // lenBuffer[0] = (byte)63;// ? ascii 是63 48 对应 0 57 对应 9 lenBuffer[0] = (byte)63;// ? ascii 是63 48 对应 0 57 对应 9 lenBuffer[1] = (byte)63; lenBuffer[2] = (byte)63; lenBuffer[3] = (byte)32;// 32 对应空字符 lenBuffer[4] = (byte)32; lenBuffer[5] = (byte)32; System.out.println ("Service socketReceiveMsgServe() received messageLength is " + new String(lenBuffer)); messageLength = Integer.valueOf((new String(lenBuffer)).trim()).intValue(); System.out.println ("messageLength : "+ messageLength); } }
运行结果
Service socketReceiveMsgServe() received messageLength is ??? Exception in thread "main" java.lang.NumberFormatException: For input string: "???" at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) at java.lang.Integer.parseInt(Integer.java:580) at java.lang.Integer.valueOf(Integer.java:766) at com.idea.rhzf.RhzfYunTest.main(RhzfYunTest.java:25)
段智华 认证博客专家 Spark AI 企业级AI技术 本人从事大数据人工智能开发和运维工作十余年,码龄5年,深入研究Spark源码,参与王家林大咖主编出版Spark+AI系列图书5本,清华大学出版社最新出版2本新书《Spark大数据商业实战三部曲:内核解密|商业案例|性能调优》第二版、《企业级AI技术内幕:深度学习框架开发+机器学习案例实战+Alluxio解密》,《企业级AI技术内幕》新书分为盘古人工智能框架开发专题篇、机器学习案例实战篇、分布式内存管理系统Alluxio解密篇。Spark新书第二版以数据智能为灵魂,包括内核解密篇,商业案例篇,性能调优篇和Spark+AI解密篇。从2015年开始撰写博文,累计原创1059篇,博客阅读量达155万次