Java FileWriter Write saveFile(File directory, String fileName, String content)

Here you can find the source of saveFile(File directory, String fileName, String content)

Description

This method save the String content in a file which name is fileName .

License

Open Source License

Parameter

Parameter Description
directory the directory in which new file will be saved.
fileName the name of the created file.
content the content saved in the created file.

Exception

Parameter Description
IOException IOException

Declaration

public static void saveFile(File directory, String fileName, String content) throws IOException 

Method Source Code

//package com.java2s;
/**/*from   w  ww  .j a  v a 2s.co  m*/
 * AADL-RAMSES
 * 
 * Copyright ? 2014 TELECOM ParisTech and CNRS
 * 
 * TELECOM ParisTech/LTCI
 * 
 * Authors: see AUTHORS
 * 
 * This program is free software: you can redistribute it and/or modify 
 * it under the terms of the Eclipse Public License as published by Eclipse,
 * either version 1.0 of the License, or (at your option) any later version.
 * 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
 * Eclipse Public License for more details.
 * You should have received a copy of the Eclipse Public License
 * along with this program.  If not, see 
 * http://www.eclipse.org/org/documents/epl-v10.php
 */

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

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

public class Main {
    /**
     * This method save the String {@code content} in a file which name is
     * {@code fileName}. The file is saved in directory {@code directory}.
     * @param directory the directory in which new file will be saved.
     * @param fileName the name of the created file.
     * @param content the content saved in the created file.
     * @throws IOException {@link IOException}
     */
    public static void saveFile(File directory, String fileName, String content) throws IOException {
        BufferedWriter output;

        FileWriter file = new FileWriter(directory.getAbsolutePath() + File.separator + fileName);

        output = new BufferedWriter(file);

        output.write(content);

        output.close();
    }
}

Related

  1. saveDictionary(String fileName, Map values)
  2. saveDotGraph(final String dotGraph, final File outputDirectory)
  3. saveDoubleArray2File(Double[] doubleArray, String fileName)
  4. saveDoubleArray2FileAppend(Double[] doubleArray, String fileName)
  5. saveEasyQuestImpl(final String quest, final File targetFile)
  6. saveFile(File file, String contents)
  7. saveFile(File file, String data)
  8. saveFile(File file, String fileContent)
  9. saveFile(File file, String text, boolean append)