Java File Append Text appendToFile(List strList, File file)

Here you can find the source of appendToFile(List strList, File file)

Description

append To File

License

Apache License

Declaration

public static void appendToFile(List<String> strList, File file)
              throws IOException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.BufferedWriter;

import java.io.Closeable;
import java.io.File;

import java.io.FileOutputStream;
import java.io.IOException;

import java.io.OutputStreamWriter;

import java.util.List;

public class Main {
    public static void appendToFile(List<String> strList, File file)
            throws IOException {
        if ((strList == null) || (strList.isEmpty()) || (file == null)) {
            return;
        }//  www  .jav  a 2s  .c  o  m
        BufferedWriter bw = null;
        try {
            bw = new BufferedWriter(new OutputStreamWriter(
                    new FileOutputStream(file, true)));
            for (String str : strList) {
                bw.write(str);
                bw.newLine();
            }
        } finally {
            close(bw);
        }
    }

    public static void close(Closeable stream) {
        if (stream == null) {
            return;
        }
        try {
            stream.close();
        } catch (IOException ioe) {
        }
    }

    public static void close(Closeable... streams) {
        if ((streams == null) || (streams.length == 0)) {
            return;
        }
        for (Closeable c : streams) {
            try {
                if (c != null) {
                    c.close();
                }
            } catch (IOException ioe) {
            }
        }
    }
}

Related

  1. appendToFile(final File file, final String contents)
  2. appendToFile(final String filePath, final String textToAppend)
  3. appendToFile(final String text, final String urlFile)
  4. appendToFile(float[] in, String filename)
  5. appendToFile(IFile file, String output)
  6. appendToFile(String baseFilename, String appendingFilename)
  7. appendToFile(String content, File file, String encoding)
  8. appendToFile(String content, String filename)
  9. appendToFile(String contents, String filename)