从终端读出来的是String,当然不能用readInt了 你可以用String s= in.readLine(); 然后int v = Integer.parseInt(s);
public int readInt() throws IOExceptionReads four input bytes and returns an int value. Let a be the first byte read, b be the second byte, c be the third byte, and d be the fourth byte. The value returned is: (((a & 0xff) << 24) | ((b & 0xff) << 16) | ((c & 0xff) << 8) | (d & 0xff)) This method is suitable for reading bytes written by the writeInt method of interface DataOutput.
你可以用String s= in.readLine();
然后int v = Integer.parseInt(s);
throws IOExceptionReads
four input bytes and returns an int value. Let a be the first byte read, b be the second byte, c be the third byte, and d be the fourth byte. The value returned is:
(((a & 0xff) << 24) | ((b & 0xff) << 16) |
((c & 0xff) << 8) | (d & 0xff))
This method is suitable for reading bytes written by the writeInt method of interface DataOutput.