Java Write String to File writeFile(String fileName, String fileData)

Here you can find the source of writeFile(String fileName, String fileData)

Description

Method writeFile.

License

Open Source License

Parameter

Parameter Description
fileName a parameter
fileData a parameter

Exception

Parameter Description
IOException an exception

Declaration

public static void writeFile(String fileName, String fileData) throws IOException 

Method Source Code


//package com.java2s;

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

import java.io.Writer;

public class Main {
    /**//from w  ww  .j a  v  a 2  s  .  com
     * Method writeFile. Writes string data to a file overwriting existing data.
     * 
     * @param fileName
     * @param fileData
     * @throws IOException
     */
    public static void writeFile(String fileName, String fileData) throws IOException {
        writeFile(fileName, fileData, false);
    }

    /**
     * Method writeFile. Writes string data to a file overwriting or appending to existing data based on the appendFlag.
     * 
     * @param fileName
     * @param fileData
     * @param appendFlag
     * @throws IOException
     */
    public static void writeFile(String fileName, String fileData, boolean appendFlag) throws IOException {
        Writer fileWriter = new FileWriter(fileName, appendFlag);
        fileWriter.write(fileData);
        fileWriter.close();
        fileWriter = null;
    }
}

Related

  1. writeFile(String fileName, String data)
  2. writeFile(String filename, String data)
  3. writeFile(String FileName, String data)
  4. writeFile(String fileName, String encoding, String content)
  5. writeFile(String fileName, String fileContent)
  6. writeFile(String fileName, String message)
  7. writeFile(String fileName, String output)
  8. writeFile(String filename, String s)
  9. writeFile(String fileName, String source)