Java Text File Write writeStringToFile(String string, File file)

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

Description

Writes a string to the file at the specified path, overwriting it if it already exists.

License

Open Source License

Parameter

Parameter Description
string the string
file the path of the file to write

Declaration

public static void writeStringToFile(String string, File file) 

Method Source Code

//package com.java2s;
/*==========================================================================*\
 |  $Id: FileUtilities.java,v 1.5 2014/06/16 15:59:40 stedwar2 Exp $
 |*-------------------------------------------------------------------------*|
 |  Copyright (C) 2006-2012 Virginia Tech
 |
 |  This file is part of Web-CAT./* w  ww .j a v a2  s.  com*/
 |
 |  Web-CAT is free software; you can redistribute it and/or modify
 |  it under the terms of the GNU Affero General Public License as published
 |  by the Free Software Foundation; either version 3 of the License, or
 |  (at your option) any later version.
 |
 |  Web-CAT 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.
 |
 |  You should have received a copy of the GNU Affero General Public License
 |  along with Web-CAT; if not, see <http://www.gnu.org/licenses/>.
\*==========================================================================*/

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

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

public class Main {
    /**
     * Writes a string to the file at the specified path, overwriting it if it
     * already exists.
     *
     * @param string the string
     * @param path the path of the file to write
     */
    public static void writeStringToFile(String string, String path) {
        writeStringToFile(string, new File(path));
    }

    /**
     * Writes a string to the file at the specified path, overwriting it if it
     * already exists.
     *
     * @param string the string
     * @param file the path of the file to write
     */
    public static void writeStringToFile(String string, File file) {
        try {
            BufferedWriter writer = new BufferedWriter(new FileWriter(file));
            writer.write(string);
            writer.close();
        } catch (IOException e) {
            // Do nothing.
        }
    }
}

Related

  1. WriteStringToFile(String str, String file)
  2. writeStringToFile(String str, String filePath)
  3. writeStringToFile(String str, String filePath)
  4. writeStringToFile(String string, File destFile)
  5. writeStringToFile(String string, File dstFile)
  6. writeStringToFile(String string, File file)
  7. writeStringToFile(String string, File file)
  8. writeStringToFile(String string, File file)
  9. writeStringToFile(String string, String fileName)