Package org.miaixz.bus.office.csv
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>
CSV文件读取器,参考:FastCSV
- Since:
- Java 17+
- Author:
- Kimi Liu
- See Also:
-
Field Summary
Fields inherited from class org.miaixz.bus.office.csv.CsvBaseReader
DEFAULT_CHARSET -
Constructor Summary
ConstructorsConstructorDescription构造,使用默认配置项CsvReader(File file, Charset charset, CsvReadConfig config) 构造CsvReader(File file, CsvReadConfig config) CsvReader(Reader reader, CsvReadConfig config) 构造CsvReader(Path path, Charset charset, CsvReadConfig config) 构造CsvReader(Path path, CsvReadConfig config) CsvReader(CsvReadConfig config) 构造 -
Method Summary
Methods inherited from class org.miaixz.bus.office.csv.CsvBaseReader
parse, read, read, read, read, read, read, read, read, readFromString, readFromString, readMapList, setContainsHeader, setErrorOnDifferentFieldCount, setFieldSeparator, setSkipEmptyRows, setTextDelimiterMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
CsvReader
public CsvReader()构造,使用默认配置项 -
CsvReader
构造- Parameters:
config- 配置项
-
CsvReader
- Parameters:
file- CSV文件路径,null表示不设置路径config- 配置项,null表示默认配置
-
CsvReader
- Parameters:
path- CSV文件路径,null表示不设置路径config- 配置项,null表示默认配置
-
CsvReader
构造- Parameters:
file- CSV文件路径,null表示不设置路径charset- 编码config- 配置项,null表示默认配置
-
CsvReader
构造- Parameters:
path- CSV文件路径,null表示不设置路径charset- 编码config- 配置项,null表示默认配置
-
CsvReader
构造- Parameters:
reader-Reader,null表示不设置默认readerconfig- 配置项,null表示默认配置
-
-
Method Details
-
read
读取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
根据Reader创建Stream,以便使用stream方式读取csv行- Returns:
Stream
-
iterator
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-