Scanner 是否有自己的读取缓冲区?
Does Scanner have its own buffer for reading?
BufferedReader
和 BufferedInputStream
有自己的读取缓冲区。有缓冲区是他们一次可以读取一行的原因吗?
Scanner
也可以一次读一行。但它不一定适用于 BufferedReader
和 BufferedInputStream
。它是否有自己的一次读取一行的缓冲区?
谢谢。
来自 Oracle's docs,特别是来自这一行:
A scanner can read text from any object which implements the Readable interface. If an invocation of the underlying readable's Readable.read(java.nio.CharBuffer) method throws an IOException then the scanner assumes that the end of the input has been reached. The most recent IOException thrown by the underlying readable can be retrieved via the ioException() method.
看来 Scanner
没有自己的缓冲区。它使用来自底层对象(实现 Readable
)的缓冲区,并使用正则表达式进行解析。
BufferedReader
和 BufferedInputStream
有自己的读取缓冲区。有缓冲区是他们一次可以读取一行的原因吗?
Scanner
也可以一次读一行。但它不一定适用于 BufferedReader
和 BufferedInputStream
。它是否有自己的一次读取一行的缓冲区?
谢谢。
来自 Oracle's docs,特别是来自这一行:
A scanner can read text from any object which implements the Readable interface. If an invocation of the underlying readable's Readable.read(java.nio.CharBuffer) method throws an IOException then the scanner assumes that the end of the input has been reached. The most recent IOException thrown by the underlying readable can be retrieved via the ioException() method.
看来 Scanner
没有自己的缓冲区。它使用来自底层对象(实现 Readable
)的缓冲区,并使用正则表达式进行解析。