Here you can find the source of writeLinesToFile(final File file, final String... lines)
Parameter | Description |
---|---|
file | the file to write to. |
lines | the lines to write to the file. |
Parameter | Description |
---|---|
IOException | if writing to the file fails. |
private static void writeLinesToFile(final File file, final String... lines) throws IOException
//package com.java2s; /**//from w w w .j a v a 2s . c o m * Copyright 2014 VU University Medical Center. * Licensed under the Apache License version 2.0 (see http://www.apache.org/licenses/LICENSE-2.0.html). */ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStreamWriter; import java.io.Writer; import java.nio.charset.StandardCharsets; public class Main { /** * New line character. */ private static final char NEW_LINE = '\n'; /** * Write lines to a file. * * @param file the file to write to. * @param lines the lines to write to the file. * @throws IOException if writing to the file fails. */ private static void writeLinesToFile(final File file, final String... lines) throws IOException { try (final Writer writer = new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8)) { for (final String line : lines) { writer.write(line); writer.write(NEW_LINE); } } } }