Java Write String to File writeFile(File f, String entry)

Here you can find the source of writeFile(File f, String entry)

Description

This method appends a single string to a text file.

License

Open Source License

Parameter

Parameter Description
f The file to write to
entry The string to append

Declaration

public static void writeFile(File f, String entry) 

Method Source Code

//package com.java2s;
/**/*from  w w w. j a  va  2 s.c o  m*/
 * <p>A utility class for writing to, and reading from, text files.</p>
 *
 * <p>This program is part of AJP-P4-2012-2013-SOLUTION.</p>
 *
 * <p>AJP-P4-2012-2013-SOLUTION is free software: you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or (at your
 * option) any later version.</p>
 *
 * <p>This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.</p>
 *
 * <p>You should have received a copy of the GNU General Public License along
 * with this program. If not, see http://www.gnu.org/licenses/.</p>
 *
 * <p>Copyright Mark Truran m.a.truran@tees.ac.uk 27-Oct-2012 </p>
 */

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

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

public class Main {
    /** This method appends a single string to a text file.
     * 
     * @param f The file to write to
     * @param entry The string to append
     */
    public static void writeFile(File f, String entry) {
        try {
            final BufferedWriter out = new BufferedWriter(new FileWriter(f, true));
            out.write(entry);
            out.close();
        } catch (IOException e) {
            System.err.println("Problem writing to the file");
        }
    }
}

Related

  1. writeFile(File f, String body)
  2. writeFile(File f, String content)
  3. writeFile(File f, String content)
  4. writeFile(File f, String content, String encoding)
  5. writeFile(File f, String contents)
  6. writeFile(File f, String s)
  7. writeFile(File f, String str)
  8. writeFile(File f, String str)
  9. writeFile(File f, String text)