Java File Append LIne appendLine(String path, String line)

Here you can find the source of appendLine(String path, String line)

Description

append Line

License

Apache License

Declaration

public static void appendLine(String path, String line)
            throws UnsupportedEncodingException, FileNotFoundException 

Method Source Code

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

import java.io.BufferedWriter;
import java.io.File;

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

import java.io.IOException;

import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.io.Writer;

public class Main {
    public static void appendLine(String path, String line)
            throws UnsupportedEncodingException, FileNotFoundException {
        File file = new File(path);
        Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file, true), "UTF-8"));

        try {/*from  w  w w  . j ava 2 s  .c  o m*/
            writer.write(line + "\n");
            writer.flush();
            writer.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Related

  1. appendLine(String filePath, String text)
  2. appendLineInFile(String path, String lines)
  3. appendLines(File file, String[] lines)
  4. appendLines(File file, String[] lines)
  5. appendLinesToFile(Iterable lines, File outFile)