Improved writeTo utils methods.

This commit is contained in:
Christian P. MOMON 2021-01-18 07:04:09 +01:00
parent 905a808aaa
commit 565af32f0b

View file

@ -1150,7 +1150,7 @@ public class StringsUtils
} }
/** /**
* Save. * Save string of the list as lines.
* *
* @param file * @param file
* the file * the file
@ -2181,7 +2181,7 @@ public class StringsUtils
* @throws IOException * @throws IOException
* Signals that an I/O exception has occurred. * 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) if (source != null)
{ {
@ -2202,7 +2202,7 @@ public class StringsUtils
* @throws IOException * @throws IOException
* Signals that an I/O exception has occurred. * 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) 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();
}
}
}
} }