zoukankan      html  css  js  c++  java
  • 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();
    }
  • 相关阅读:
    进程与线程的区别
    信号列表详解
    同步与互斥
    互斥锁
    读写锁
    Redis QPS测试
    从分布式锁来看redis和zookpeer!
    JVM虚拟机调参
    log4j.properties配置详解与实例
    生产者消费者(消费者要消费完才能退出)
  • 原文地址:https://www.cnblogs.com/lijia0511/p/5778307.html
Copyright © 2011-2022 走看看