Java File Append Text appendToFile(String sb, String directory, String fileName)

Here you can find the source of appendToFile(String sb, String directory, String fileName)

Description

append To File

License

Open Source License

Declaration

public static void appendToFile(String sb, String directory, String fileName) 

Method Source Code


//package com.java2s;
import java.io.*;

public class Main {
    public static void appendToFile(String sb, String directory, String fileName) {
        if (!directory.endsWith("/")) {
            directory = directory + "/";
        }/*from www  . j  av  a2s.com*/
        File out = new File(directory + fileName);
        //System.out.println(directory+fileName);
        try {
            Writer fw = new OutputStreamWriter(new FileOutputStream(out, true), "UTF-8");
            try {
                fw.write(sb.toString());
                fw.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }

    }
}

Related

  1. appendToFile(String fileName, String text)
  2. appendToFile(String filename, String text)
  3. appendToFile(String filePath, String content)
  4. appendToFile(String filePath, String data)
  5. appendToFile(String filepath, String newLine)
  6. appendToFile(String str, String filename, boolean appendNewLine)
  7. appendToFile(String string, File file)
  8. appendToFile(String text, String fileName)
  9. appendToString(final byte b, final Appendable ap)