BufferedReader.read()
BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
System.out.println(reader.read());
- 今天在用这个方法的时候看到返回的类型正好的int,然后直接用来读取int结果导致后面出现了莫名其妙的错误
仔细看了一下API发现我理解错了
public int read()
throws IOExceptionReads a single character.
Overrides:
read in class Reader
Returns:
The character read, as an integer in the range 0 to 65535 (0x00-0xffff), or -1 if the end of the stream has been reached
Throws:
IOException - If an I/O error occurs
- 文档说的是读取一个character as an integer,就是把你输入的当做字符,然后返回他对应的ASCII码值,比如你输入5,打印的是53,而且不管你输入的数字多大,只会读取第一个字符。 ̄□ ̄||