Java OutputStreamWriter Write save(String fileContent, File file, String encoding)

Here you can find the source of save(String fileContent, File file, String encoding)

Description

Saves a string to a text file.

License

Open Source License

Parameter

Parameter Description
fileContent - the file content string
file - the target file
encoding - the text encoding

Exception

Parameter Description
IOException an exception

Declaration

public static void save(String fileContent, File file, String encoding) throws IOException 

Method Source Code


//package com.java2s;
/*// w w w. ja  v  a2 s .c  o m
 * This file is part of Pustefix.
 *
 * Pustefix 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 2 of the License, or
 * (at your option) any later version.
 *
 * Pustefix 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 Pustefix; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

import java.io.File;

import java.io.FileOutputStream;
import java.io.IOException;

import java.io.OutputStreamWriter;

public class Main {
    /**
     * Saves a string to a text file.
     * 
     * @param fileContent - the file content string
     * @param file - the target file
     * @param encoding - the text encoding
     * @throws IOException
     */
    public static void save(String fileContent, File file, String encoding) throws IOException {
        FileOutputStream fos = new FileOutputStream(file);
        OutputStreamWriter writer = new OutputStreamWriter(fos, encoding);
        try {
            writer.write(fileContent);
            writer.flush();
        } finally {
            fos.close();
        }
    }
}

Related

  1. save(String text, File out)
  2. saveCache()
  3. saveDocument(String path, String textToWrite)
  4. saveFile(File file, String whatToSave, String encoding)