FileWriter增加方法,可选是否追加换行符(issue#3858@Github)

This commit is contained in:
Looly 2025-02-18 19:01:56 +08:00
parent f3c97bdc4d
commit 6e83e67a4a
2 changed files with 28 additions and 5 deletions

View File

@ -237,13 +237,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;
}

View File

@ -0,0 +1,24 @@
package cn.hutool.core.io.file;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.io.FileUtil;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
public class FileWriterTest {
@Test
@Disabled
void writeLinesAppendLineSeparatorTest() {
final FileWriter writer = FileWriter.create(FileUtil.file("d:/test/lines_append_line_separator.txt"));
writer.writeLines(ListUtil.of("aaa", "bbb", "ccc"), null, false, true);
}
@Test
@Disabled
void writeLinesTest() {
final FileWriter writer = FileWriter.create(FileUtil.file("d:/test/lines.txt"));
writer.writeLines(ListUtil.of("aaa", "bbb", "ccc"), null, false);
}
}