Java Text File Append appendStringToFile(File file, String string)

Here you can find the source of appendStringToFile(File file, String string)

Description

append String To File

License

Creative Commons License

Declaration

public static void appendStringToFile(File file, String string) 

Method Source Code

//package com.java2s;
/**//from w  w w  .  j av a2  s .  c  om
 * Copyright 2013-2014 by ATLauncher and Contributors
 *
 * This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License.
 * To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/.
 */

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

public class Main {
    public static void appendStringToFile(File file, String string) {
        FileWriter fw = null;
        BufferedWriter bw = null;
        PrintWriter pw = null;
        try {
            fw = new FileWriter(file, true);
            bw = new BufferedWriter(fw);
            pw = new PrintWriter(bw);
            pw.println(string);
            pw.close();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (fw != null) {
                    fw.close();
                }
                if (bw != null) {
                    bw.close();
                }
                if (pw != null) {
                    pw.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

Related

  1. add2File(String fileName, String content)
  2. appendStringToFile(File f, String s)
  3. appendStringToFile(File file, String string)
  4. appendStringToFile(File file, String string)
  5. appendStringToFile(final String path, final String output)
  6. appendStringToFile(String file, String contents)
  7. appendStringToFile(String fileName, String data)