如果您阅读了源代码,则可以自己回答问题。
public Scanner(File source) throws FileNotFoundException { this((ReadableByteChannel)(new FileInputStream(source).getChannel()));}
后者包装在阅读器中:
private static Readable makeReadable(ReadableByteChannel source, CharsetDeprer 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)); }
因此,看来扫描仪不会一次读取整个文件。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)