Java File Append LIne appendLineInFile(String path, String lines)

Here you can find the source of appendLineInFile(String path, String lines)

Description

append Line In File

License

Open Source License

Parameter

Parameter Description
path of the file to open
lines to append

Declaration

public static void appendLineInFile(String path, String lines) 

Method Source Code

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

import java.io.DataOutputStream;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;

import java.io.IOException;

public class Main {
    /**/* w  w w  .j  a va  2s  .co  m*/
     * 
     * @param path of the file to open
     * @param lines to append
     */
    public static void appendLineInFile(String path, String lines) {
        FileOutputStream fouts;
        try {
            fouts = new FileOutputStream(path, true);

            DataOutputStream douts = new DataOutputStream(fouts);
            douts.writeBytes(lines.toString());
            douts.flush();
            douts.close();
            fouts.close();
        } catch (FileNotFoundException e) {

            e.printStackTrace();
        } catch (IOException e) {

            e.printStackTrace();
        }

    }
}

Related

  1. appendLine(String filePath, String text)
  2. appendLine(String path, String line)
  3. appendLines(File file, String[] lines)
  4. appendLines(File file, String[] lines)
  5. appendLinesToFile(Iterable lines, File outFile)
  6. appendLineToFile(String fileName, String format, Object... vals)