あなたがあなた自身で質問に答えることができます。
問題のスキャナコンストラクタの実装が示しているように見える:
public Scanner(File source) throws FileNotFoundException {
this((ReadableByteChannel)(new FileInputStream(source).getChannel()));
}
後者これはリーダーにラップされています
private static Readable makeReadable(ReadableByteChannel source, CharsetDecoder dec) {
return Channels.newReader(source, dec, -1);
}
そして、それはバッファサイズ
を使用して読み込まれます
private static final int BUFFER_SIZE = 1024; // change to 1024;
建設連鎖の最終コンストラクタで確認できますように:
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));
}
したがって、スキャナはファイル全体を一度に読み取らないようです。
答えはいいですが、バッファでファイルを読み取ります。つまり、チャンクであることを意味します。 – Alex