Files
guava源码:Files
看一下它的调用过程
public static <T> T readLines(File file, Charset charset,
LineProcessor<T> callback) throws IOException {
return asCharSource(file, charset).readLines(callback);
}
asCharSource->asByteSource->FileByteSource
FileByteSource里 是用的FIleInputStream
@Override
public FileInputStream openStream() throws IOException {
return new FileInputStream(file);
}
在asByteSource里 对FIleByteSource转换 成BufferedReader
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();
}