mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
FileWriter
增加方法,可选是否追加换行符(issue#3858@Github)
This commit is contained in:
parent
fcab6e6340
commit
3ec1b3745d
@ -204,7 +204,7 @@ public class FileWriter extends FileWrapper {
|
||||
* @since 3.1.0
|
||||
*/
|
||||
public <T> File writeLines(final Iterable<T> list, final LineSeparator lineSeparator, final boolean isAppend) throws IORuntimeException {
|
||||
return writeLines(list, lineSeparator, isAppend, false);
|
||||
return writeLines(list, lineSeparator, isAppend, true);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -234,13 +234,12 @@ public class FileWriter extends FileWrapper {
|
||||
printNewLine(writer, lineSeparator);
|
||||
}
|
||||
writer.print(t);
|
||||
if(appendLineSeparator){
|
||||
printNewLine(writer, lineSeparator);
|
||||
}
|
||||
|
||||
writer.flush();
|
||||
}
|
||||
}
|
||||
if(appendLineSeparator){
|
||||
printNewLine(writer, lineSeparator);
|
||||
}
|
||||
writer.flush();
|
||||
}
|
||||
return this.file;
|
||||
}
|
||||
|
@ -0,0 +1,21 @@
|
||||
package org.dromara.hutool.core.io.file;
|
||||
|
||||
import org.dromara.hutool.core.collection.ListUtil;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class FileWriterTest {
|
||||
@Test
|
||||
@Disabled
|
||||
void writeLinesAppendLineSeparatorTest() {
|
||||
final FileWriter writer = FileWriter.of(FileUtil.file("d:/test/lines_append_line_separator.txt"));
|
||||
writer.writeLines(ListUtil.of("aaa", "bbb", "ccc"), null, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled
|
||||
void writeLinesTest() {
|
||||
final FileWriter writer = FileWriter.of(FileUtil.file("d:/test/lines.txt"));
|
||||
writer.writeLines(ListUtil.of("aaa", "bbb", "ccc"), null, false, false);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user