If you read the source code, you can answer the question yourself.
It seems that the implementation of the Scanner constructor in question shows:
public Scanner(File source) throws FileNotFoundException { this((ReadableByteChannel)(new FileInputStream(source).getChannel())); }
The last wrapped in Reader:
private static Readable makeReadable(ReadableByteChannel source, CharsetDecoder dec) { return Channels.newReader(source, dec, -1); }
And it is read using buffer size
private static final int BUFFER_SIZE = 1024;
As you can see in the final constructor in the build chain:
private Scanner(Readable source, Pattern pattern) { assert source != null : "source should not be null"; assert pattern != null : "pattern should not be null"; this.source = source; delimPattern = pattern; buf = CharBuffer.allocate(BUFFER_SIZE); buf.limit(0); matcher = delimPattern.matcher(buf); matcher.useTransparentBounds(true); matcher.useAnchoringBounds(false); useLocale(Locale.getDefault(Locale.Category.FORMAT)); }
So, it seems that the scanner is not reading the entire file at once.
source share