public final class CsvWriter extends Object implements Closeable, Flushable, Serializable
Constructor and Description |
---|
CsvWriter(File file)
构造,覆盖已有文件(如果存在),默认编码UTF-8
|
CsvWriter(File file,
Charset charset)
构造,覆盖已有文件(如果存在)
|
CsvWriter(File file,
Charset charset,
boolean isAppend)
构造
|
CsvWriter(File file,
Charset charset,
boolean isAppend,
CsvWriteConfig config)
构造
|
CsvWriter(String filePath)
构造,覆盖已有文件(如果存在),默认编码UTF-8
|
CsvWriter(String filePath,
Charset charset)
构造,覆盖已有文件(如果存在)
|
CsvWriter(String filePath,
Charset charset,
boolean isAppend)
构造
|
CsvWriter(String filePath,
Charset charset,
boolean isAppend,
CsvWriteConfig config)
构造
|
CsvWriter(Writer writer)
构造,使用默认配置
|
CsvWriter(Writer writer,
CsvWriteConfig config)
构造
|
Modifier and Type | Method and Description |
---|---|
void |
close() |
void |
flush() |
CsvWriter |
setAlwaysDelimitText(boolean alwaysDelimitText)
设置是否始终使用文本分隔符,文本包装符,默认false,按需添加
|
CsvWriter |
setLineDelimiter(char[] lineDelimiter)
设置换行符
|
CsvWriter |
write(CsvData csvData)
将一个 CsvData 集合写出到Writer
|
CsvWriter |
write(Iterable<?> lines)
将多行写出到Writer
|
CsvWriter |
write(String[]... lines)
将多行写出到Writer
|
CsvWriter |
writeBeans(Iterable<?> beans)
将一个Bean集合写出到Writer,并自动生成表头
|
CsvWriter |
writeBeans(Iterable<?> beans,
boolean writeHeaderLine,
String... properties)
将一个Bean集合写出到Writer,并自动生成表头
|
CsvWriter |
writeBeans(Iterable<?> beans,
String... properties)
将一个Bean集合写出到Writer,并自动生成表头
|
CsvWriter |
writeComment(String comment)
写出一行注释,注释符号可自定义
如果注释符不存在,则抛出异常 |
CsvWriter |
writeHeaderLine(String... fields)
写出一行头部行,支持标题别名
|
CsvWriter |
writeLine()
追加新行(换行)
|
CsvWriter |
writeLine(String... fields)
写出一行
|
public CsvWriter(String filePath)
filePath
- File CSV文件路径public CsvWriter(File file)
file
- File CSV文件public CsvWriter(String filePath, Charset charset)
filePath
- File CSV文件路径charset
- 编码public CsvWriter(File file, Charset charset)
file
- File CSV文件charset
- 编码public CsvWriter(String filePath, Charset charset, boolean isAppend)
filePath
- File CSV文件路径charset
- 编码isAppend
- 是否追加public CsvWriter(File file, Charset charset, boolean isAppend)
file
- CSV文件charset
- 编码isAppend
- 是否追加public CsvWriter(String filePath, Charset charset, boolean isAppend, CsvWriteConfig config)
filePath
- CSV文件路径charset
- 编码isAppend
- 是否追加config
- 写出配置,null则使用默认配置public CsvWriter(File file, Charset charset, boolean isAppend, CsvWriteConfig config)
file
- CSV文件charset
- 编码isAppend
- 是否追加,append模式下,endingLineBreak自动设置为trueconfig
- 写出配置,null则使用默认配置public CsvWriter(Writer writer, CsvWriteConfig config)
writer
- Writerconfig
- 写出配置,null则使用默认配置public CsvWriter setAlwaysDelimitText(boolean alwaysDelimitText)
alwaysDelimitText
- 是否始终使用文本分隔符,文本包装符,默认false,按需添加public CsvWriter setLineDelimiter(char[] lineDelimiter)
lineDelimiter
- 换行符public CsvWriter write(String[]... lines) throws IORuntimeException
lines
- 多行数据IORuntimeException
- IO异常public CsvWriter write(Iterable<?> lines) throws IORuntimeException
lines
- 多行数据,每行数据可以是集合或者数组IORuntimeException
- IO异常public CsvWriter write(CsvData csvData)
csvData
- CsvDatapublic CsvWriter writeBeans(Iterable<?> beans)
beans
- Bean集合public CsvWriter writeBeans(Iterable<?> beans, String... properties)
beans
- Bean集合properties
- Bean 中指定的可以导出的属性public CsvWriter writeBeans(Iterable<?> beans, boolean writeHeaderLine, String... properties)
beans
- Bean集合writeHeaderLine
- 是否写出表头,即Bean的字段名称列表作为首行properties
- Bean 中指定的可以导出的属性public CsvWriter writeHeaderLine(String... fields) throws IORuntimeException
fields
- 字段列表 (null
值会被做为空值追加IORuntimeException
- IO异常public CsvWriter writeLine(String... fields) throws IORuntimeException
fields
- 字段列表 (null
值会被做为空值追加)IORuntimeException
- IO异常public CsvWriter writeLine() throws IORuntimeException
IORuntimeException
- IO异常public CsvWriter writeComment(String comment)
comment
- 注释内容CsvConfig.commentCharacter
public void close()
close
in interface Closeable
close
in interface AutoCloseable
public void flush() throws IORuntimeException
flush
in interface Flushable
IORuntimeException
Copyright © 2024. All rights reserved.