diff --git a/hutool-core/src/main/java/cn/hutool/core/io/file/FileWriter.java b/hutool-core/src/main/java/cn/hutool/core/io/file/FileWriter.java index 26445629a..5755745e1 100644 --- a/hutool-core/src/main/java/cn/hutool/core/io/file/FileWriter.java +++ b/hutool-core/src/main/java/cn/hutool/core/io/file/FileWriter.java @@ -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; } diff --git a/hutool-core/src/test/java/cn/hutool/core/io/file/FileWriterTest.java b/hutool-core/src/test/java/cn/hutool/core/io/file/FileWriterTest.java new file mode 100644 index 000000000..ccda2b7e1 --- /dev/null +++ b/hutool-core/src/test/java/cn/hutool/core/io/file/FileWriterTest.java @@ -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); + } + +}