guava源碼:Filesjava
看一下它的調用過程ide
public static <T> T readLines(File file, Charset charset, LineProcessor<T> callback) throws IOException { return asCharSource(file, charset).readLines(callback); }
asCharSource->asByteSource->FileByteSourcespa
FileByteSource裏 是用的FIleInputStreamcode
@Override
public FileInputStream openStream() throws IOException { return new FileInputStream(file); }
在asByteSource裏 對FIleByteSource轉換 成BufferedReaderget
public static BufferedReader newReader(File file, Charset charset) throws FileNotFoundException { checkNotNull(file); checkNotNull(charset); return new BufferedReader( new InputStreamReader(new FileInputStream(file), charset)); }
在ReadLines中源碼
public static <T> T readLines( Readable readable, LineProcessor<T> processor) throws IOException { checkNotNull(readable); checkNotNull(processor); LineReader lineReader = new LineReader(readable); String line; while ((line = lineReader.readLine()) != null) { if (!processor.processLine(line)) { break; } } return processor.getResult(); }