Class CsvReader

java.lang.Object
org.miaixz.bus.office.csv.CsvBaseReader
org.miaixz.bus.office.csv.CsvReader
All Implemented Interfaces:
Closeable, Serializable, AutoCloseable, Iterable<CsvRow>

public class CsvReader extends CsvBaseReader implements Iterable<CsvRow>, Closeable
CSV文件读取器,参考:FastCSV
Since:
Java 17+
Author:
Kimi Liu
See Also:
  • Constructor Details

    • CsvReader

      public CsvReader()
      构造,使用默认配置项
    • CsvReader

      public CsvReader(CsvReadConfig config)
      构造
      Parameters:
      config - 配置项
    • CsvReader

      public CsvReader(File file, CsvReadConfig config)
      构造,默认CsvBaseReader.DEFAULT_CHARSET编码
      Parameters:
      file - CSV文件路径,null表示不设置路径
      config - 配置项,null表示默认配置
    • CsvReader

      public CsvReader(Path path, CsvReadConfig config)
      构造,默认CsvBaseReader.DEFAULT_CHARSET编码
      Parameters:
      path - CSV文件路径,null表示不设置路径
      config - 配置项,null表示默认配置
    • CsvReader

      public CsvReader(File file, Charset charset, CsvReadConfig config)
      构造
      Parameters:
      file - CSV文件路径,null表示不设置路径
      charset - 编码
      config - 配置项,null表示默认配置
    • CsvReader

      public CsvReader(Path path, Charset charset, CsvReadConfig config)
      构造
      Parameters:
      path - CSV文件路径,null表示不设置路径
      charset - 编码
      config - 配置项,null表示默认配置
    • CsvReader

      public CsvReader(Reader reader, CsvReadConfig config)
      构造
      Parameters:
      reader - Reader,null表示不设置默认reader
      config - 配置项,null表示默认配置
  • Method Details

    • read

      public CsvData read() throws org.miaixz.bus.core.lang.exception.InternalException
      读取CSV文件,此方法只能调用一次 调用此方法的前提是构造中传入文件路径或Reader
      Returns:
      CsvData,包含数据列表和行信息
      Throws:
      org.miaixz.bus.core.lang.exception.InternalException - IO异常
    • read

      public void read(org.miaixz.bus.core.center.function.ConsumerX<CsvRow> rowHandler) throws org.miaixz.bus.core.lang.exception.InternalException
      读取CSV数据,此方法只能调用一次 调用此方法的前提是构造中传入文件路径或Reader
      Parameters:
      rowHandler - 行处理器,用于一行一行的处理数据
      Throws:
      org.miaixz.bus.core.lang.exception.InternalException - IO异常
    • stream

      public Stream<CsvRow> stream()
      根据Reader创建Stream,以便使用stream方式读取csv行
      Returns:
      Stream
    • iterator

      public Iterator<CsvRow> iterator()
      Specified by:
      iterator in interface Iterable<CsvRow>
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable