mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +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 {
|
public BufferedWriter getWriter(boolean isAppend) throws IORuntimeException {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
return new BufferedWriter(new OutputStreamWriter(new FileOutputStream(FileUtil.touch(file), isAppend), charset));
|
return new BufferedWriter(new OutputStreamWriter(new FileOutputStream(FileUtil.touch(file), isAppend), charset));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new IORuntimeException(e);
|
throw new IORuntimeException(e);
|
||||||
|
@ -130,11 +130,11 @@ public final class CsvWriter implements Closeable, Flushable, Serializable {
|
|||||||
*
|
*
|
||||||
* @param file CSV文件
|
* @param file CSV文件
|
||||||
* @param charset 编码
|
* @param charset 编码
|
||||||
* @param isAppend 是否追加
|
* @param isAppend 是否追加,append模式下,endingLineBreak自动设置为true
|
||||||
* @param config 写出配置,null则使用默认配置
|
* @param config 写出配置,null则使用默认配置
|
||||||
*/
|
*/
|
||||||
public CsvWriter(File file, Charset charset, boolean isAppend, CsvWriteConfig config) {
|
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();
|
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…
x
Reference in New Issue
Block a user