Java File Append appendFileLines(String fileName, String[] data)

Here you can find the source of appendFileLines(String fileName, String[] data)

Description

{ method

License

Apache License

Parameter

Parameter Description
f non-null of file to create
data non-null array of lines to write

Return

true = success }

Declaration

public static boolean appendFileLines(String fileName, String[] data) 

Method Source Code

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

import java.io.*;

public class Main {
    /**// w ww . ja v  a2  s  .c  o  m
     * { method
     *
     * @param f    non-null  of file to create
     * @param data non-null array of lines to write
     * @return true = success
     *         }
     * @name appendFileLines
     * @function append the string data to the file Filename
     */
    public static boolean appendFileLines(String fileName, String[] data) {
        return appendFileLines(new File(fileName), data);
    }

    /**
     * { method
     *
     * @param f    non-null  of file to create
     * @param data non-null array of lines to write
     * @return true = success
     *         }
     * @name writeFileLines
     * @function write the string data to the file Filename
     */
    public static boolean appendFileLines(File f, String[] data) {
        try {
            PrintWriter out = openAppendPrintWriter(f);
            if (out != null) {
                for (int i = 0; i < data.length; i++)
                    out.println(data[i]);
                out.close();
                return (true);
            }
            return (false);
            // failure
        } catch (SecurityException ex) {
            return (false); // browser disallows
        }
    }

    /**
     * { method
     *
     * @param name name of file
     * @return the stream - null for failure
     *         }
     * @name openPrintWriter
     * @function open a PrintWriter to a file with name
     */
    public static PrintWriter openAppendPrintWriter(File name) {
        FileOutputStream file = null;
        try {
            file = new FileOutputStream(name, true);
            return new PrintWriter(new BufferedOutputStream(file));
        } catch (SecurityException ee) {
            return (null);
        } catch (IOException ee) {
            return (null);
        }
    }
}

Related

  1. appendFile(String path, String sb)
  2. appendFile(String source, String filetoappend)
  3. appendFile(String strThrift, String filePath)
  4. appendFileBytes(String srcFileName, String tarFileName)
  5. appendFileContent(File file, String content, boolean append)
  6. appendFilePart(File dstFile, byte[] bytes)
  7. appendHex(A sb, byte[] array, int offset, int len, char sep)
  8. appendHexJavaScriptRepresentation(Appendable out, int codePoint)
  9. appendHexJavaScriptRepresentation(StringBuilder sb, char c)