mirror of
https://gitee.com/dromara/hutool.git
synced 2025-05-07 22:27:59 +08:00
add method
This commit is contained in:
parent
f85f29174d
commit
c5673bb06b
@ -206,9 +206,18 @@ public class FileWriter extends FileWrapper {
|
|||||||
*/
|
*/
|
||||||
public <T> File writeLines(Iterable<T> list, LineSeparator lineSeparator, boolean isAppend) throws IORuntimeException {
|
public <T> File writeLines(Iterable<T> list, LineSeparator lineSeparator, boolean isAppend) throws IORuntimeException {
|
||||||
try (PrintWriter writer = getPrintWriter(isAppend)) {
|
try (PrintWriter writer = getPrintWriter(isAppend)) {
|
||||||
|
boolean isFirst = true;
|
||||||
for (T t : list) {
|
for (T t : list) {
|
||||||
if (null != t) {
|
if (null != t) {
|
||||||
|
if(isFirst){
|
||||||
|
isFirst = false;
|
||||||
|
if(isAppend && FileUtil.isNotEmpty(this.file)){
|
||||||
|
// 追加模式下且文件非空,补充换行符
|
||||||
printNewLine(writer, lineSeparator);
|
printNewLine(writer, lineSeparator);
|
||||||
|
}
|
||||||
|
} else{
|
||||||
|
printNewLine(writer, lineSeparator);
|
||||||
|
}
|
||||||
writer.print(t);
|
writer.print(t);
|
||||||
|
|
||||||
writer.flush();
|
writer.flush();
|
||||||
|
Loading…
Reference in New Issue
Block a user