From 565af32f0b97294a29a4bb7a2f081f1552e2718f Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Mon, 18 Jan 2021 07:04:09 +0100 Subject: [PATCH] Improved writeTo utils methods. --- src/fr/devinsy/strings/StringsUtils.java | 44 +++++++++++++++++++++--- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/src/fr/devinsy/strings/StringsUtils.java b/src/fr/devinsy/strings/StringsUtils.java index f752f58..7b41537 100644 --- a/src/fr/devinsy/strings/StringsUtils.java +++ b/src/fr/devinsy/strings/StringsUtils.java @@ -1150,8 +1150,8 @@ public class StringsUtils } /** - * Save. - * + * Save string of the list as lines. + * * @param file * the file * @param source @@ -2181,7 +2181,7 @@ public class StringsUtils * @throws IOException * Signals that an I/O exception has occurred. */ - public static void writeTo(final StringList source, final java.io.PrintWriter out) throws IOException + public static void writeTo(final java.io.PrintWriter out, final StringList source) throws IOException { if (source != null) { @@ -2202,7 +2202,7 @@ public class StringsUtils * @throws IOException * Signals that an I/O exception has occurred. */ - public static void writeTo(final StringList source, final java.io.Writer out) throws IOException + public static void writeTo(final java.io.Writer out, final StringList source) throws IOException { if (source != null) { @@ -2212,4 +2212,40 @@ public class StringsUtils } } } + + /** + * Save. + * + * @param file + * the file + * @param source + * the source + * @throws UnsupportedEncodingException + * the unsupported encoding exception + * @throws FileNotFoundException + * the file not found exception + */ + public static void writeToFile(final File file, final StringList source) throws UnsupportedEncodingException, FileNotFoundException + { + PrintWriter out = null; + try + { + out = new PrintWriter(new OutputStreamWriter(new FileOutputStream(file), DEFAULT_CHARSET_NAME)); + + if (source != null) + { + for (String string : source) + { + out.print(string); + } + } + } + finally + { + if (out != null) + { + out.close(); + } + } + } }