mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-05 17:37:59 +08:00
CsvWriter如果开启了append=true,默认自动开启endingLineBreak=true
This commit is contained in:
parent
3603fdaeea
commit
2e1ed51f28
@ -376,6 +376,7 @@ public class FileWriter extends FileWrapper {
|
||||
*/
|
||||
public BufferedWriter getWriter(boolean isAppend) throws IORuntimeException {
|
||||
try {
|
||||
|
||||
return new BufferedWriter(new OutputStreamWriter(new FileOutputStream(FileUtil.touch(file), isAppend), charset));
|
||||
} catch (Exception e) {
|
||||
throw new IORuntimeException(e);
|
||||
|
@ -130,11 +130,11 @@ public final class CsvWriter implements Closeable, Flushable, Serializable {
|
||||
*
|
||||
* @param file CSV文件
|
||||
* @param charset 编码
|
||||
* @param isAppend 是否追加
|
||||
* @param isAppend 是否追加,append模式下,endingLineBreak自动设置为true
|
||||
* @param config 写出配置,null则使用默认配置
|
||||
*/
|
||||
public CsvWriter(File file, Charset charset, boolean isAppend, CsvWriteConfig config) {
|
||||
this(FileUtil.getWriter(file, charset, isAppend), config);
|
||||
this(FileUtil.getWriter(file, charset, isAppend), isAppend?(config==null?CsvWriteConfig.defaultConfig().setEndingLineBreak(true):config.setEndingLineBreak(true)):config);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -44,4 +44,20 @@ public class CsvWriterTest {
|
||||
}
|
||||
writer.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void writeAppendTest(){
|
||||
final CsvWriter writer = CsvUtil.getWriter(
|
||||
FileUtil.file("d:/test/writeAppendTest.csv"),
|
||||
CharsetUtil.CHARSET_GBK, true);
|
||||
|
||||
writer.writeHeaderLine("name", "gender", "address");
|
||||
writer.writeLine("张三", "男", "XX市XX区");
|
||||
writer.writeLine("李四", "男", "XX市XX区,01号");
|
||||
|
||||
writer.writeLine("张三2", "男", "XX市XX区");
|
||||
writer.writeLine("李四2", "男", "XX市XX区,01号");
|
||||
writer.close();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user