From 6e83e67a4ae402cbf4fece629ce5021b12387d48 Mon Sep 17 00:00:00 2001 From: Looly Date: Tue, 18 Feb 2025 19:01:56 +0800 Subject: [PATCH] =?UTF-8?q?`FileWriter`=E5=A2=9E=E5=8A=A0=E6=96=B9?= =?UTF-8?q?=E6=B3=95=EF=BC=8C=E5=8F=AF=E9=80=89=E6=98=AF=E5=90=A6=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0=E6=8D=A2=E8=A1=8C=E7=AC=A6=EF=BC=88issue#3858@Github?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cn/hutool/core/io/file/FileWriter.java | 9 ++++--- .../hutool/core/io/file/FileWriterTest.java | 24 +++++++++++++++++++ 2 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 hutool-core/src/test/java/cn/hutool/core/io/file/FileWriterTest.java 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); + } + +}