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();
    }
  • 相关阅读:
    1028 人口普查 (20分)
    1027 打印沙漏 (20分)
    1026 程序运行时间 (15分)
    1025 反转链表 (25分)
    1024 科学计数法 (20分)
    1023 组个最小数 (20分)
    1022 D进制的A+B (20分)
    1021 个位数统计 (15分)
    1020 月饼 (25分)
    1019 数字黑洞 (20分)
  • 原文地址:https://www.cnblogs.com/lijia0511/p/5778307.html
Copyright © 2011-2022 走看看