Java File Append Text appendTextToFile(String file_name, String text)

Here you can find the source of appendTextToFile(String file_name, String text)

Description

append Text To File

License

Open Source License

Declaration

static public void appendTextToFile(String file_name, String text) throws IOException 

Method Source Code

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

import java.io.File;

import java.io.FileWriter;
import java.io.IOException;

public class Main {
    static public void appendTextToFile(String file_name, String text) throws IOException {
        appendTextToFile(new File(file_name), text);
    }//from   w  ww  .j a va2 s. com

    /**
     * @param file
     * @param text
     * @throws IOException
     */
    static public void appendTextToFile(File file, String text) {
        try {
            FileWriter writer = new FileWriter(file, true);

            for (int i = 0; i < text.length(); i++) {
                int ch = (int) text.charAt(i);
                writer.write(ch);
            }

            writer.write('\n');

            writer.flush();
            writer.close();
        } catch (IOException e) {
            System.err.println("\nError of append_to_file  [" + file + "]: \n" + e);
        }
    }
}

Related

  1. appendText(String path, String text)
  2. appendTextString(File outputFile, String doc)
  3. appendTextToFile(@Nonnull File target, String text)
  4. appendTextToFile(File fileToAppend, Set linesToAppend)
  5. appendTextToFile(String file, String text)
  6. appendTextToFile(String filename, String data)
  7. AppendTextToFile(String filePath, String text)
  8. appendTextToFile(String text, File file)
  9. appendToFile(File destFile, InputStream source)