Java File Append LIne appendLinesToFile(Iterable lines, File outFile)

Here you can find the source of appendLinesToFile(Iterable lines, File outFile)

Description

Append a bunch of String to a new File, line by line.

License

Open Source License

Parameter

Parameter Description
lines a parameter
outFile a parameter

Exception

Parameter Description
IOException an exception

Declaration

public static void appendLinesToFile(Iterable<String> lines, File outFile) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.*;

public class Main {
    /**/*from  w  ww  .  jav  a2 s  . co m*/
     * Append a bunch of String to a new File, line by line. If necessary, the file is created.
     * 
     * @param lines
     * @param outFile
     * @throws IOException
     */
    public static void appendLinesToFile(Iterable<String> lines, File outFile) throws IOException {
        if (outFile == null || lines == null)
            throw new IOException("Got null args");

        outFile.createNewFile();
        PrintWriter pw = new PrintWriter(new FileOutputStream(outFile, true));
        try {
            for (String line : lines)
                pw.println(line);
        } finally {
            pw.close();
        }
    }
}

Related

  1. appendLine(String filePath, String text)
  2. appendLine(String path, String line)
  3. appendLineInFile(String path, String lines)
  4. appendLines(File file, String[] lines)
  5. appendLines(File file, String[] lines)
  6. appendLineToFile(String fileName, String format, Object... vals)
  7. AppendLineToFile(String filePath, String text)
  8. appendLineToFile(String path, String line)
  9. appendLineToTextFile(File file, String line)