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)