Java Text File Write writeStringToFile(File f, String s)

Here you can find the source of writeStringToFile(File f, String s)

Description

Writes a string to a file

License

Open Source License

Declaration

public static void writeStringToFile(File f, String s)
        throws IOException 

Method Source Code

//package com.java2s;
/**/*  w w w.j  a  v  a2s .c om*/
 * AC - A source-code copy detector
 *
 *     For more information please visit:  http://github.com/manuel-freire/ac
 *
 * ****************************************************************************
 *
 * This file is part of AC, version 2.0
 *
 * AC is free software: you can redistribute it and/or modify it under the
 * terms of the GNU Lesser General Public License as published by the
 * Free Software Foundation, either version 3 of the License,
 * or (at your option) any later version.
 *
 * AC 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 Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with AC.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.io.*;

public class Main {
    public static String DEFAULT_FILE_ENCODING = "UTF-8";

    /**
     * Writes a string to a file
     */
    public static void writeStringToFile(File f, String s)
            throws IOException {
        FileOutputStream fos = new FileOutputStream(f);
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos,
                DEFAULT_FILE_ENCODING));
        bw.write(s);
        bw.close();
    }
}

Related

  1. writeStringTo(File outFile, String data)
  2. writeStringTo(String _value, File _target)
  3. writeStringToFile(@Nonnull String string, @Nonnull final File file)
  4. writeStringToFile(CharSequence contents, String filename)
  5. writeStringToFile(File f, String content, boolean append)
  6. writeStringToFile(File f, String s)
  7. writeStringToFile(File f, String s)
  8. writeStringToFile(File file, String content)
  9. writeStringToFile(File file, String content)