Java Write String to File writeFile(String contents, String filename)

Here you can find the source of writeFile(String contents, String filename)

Description

Writes the given string into the given file.

License

Open Source License

Parameter

Parameter Description
contents String representing the file contents.
filename Name of the file to be written.

Exception

Parameter Description
IOException an exception

Declaration

public static void writeFile(String contents, String filename)
        throws IOException 

Method Source Code

//package com.java2s;

import java.io.*;

public class Main {
    /**//from ww w  . ja  va 2 s  .c o  m
     * Writes the given string into the given file.
     *
     * @param contents String representing the file contents.
     * @param filename Name of the file to be written.
     * @throws IOException
     */
    public static void writeFile(String contents, String filename)
            throws IOException {
        FileWriter fw = new FileWriter(filename);
        fw.write(contents);
        fw.flush();
        fw.close();
    }
}

Related

  1. writeFile(String content, String targetfileName)
  2. writeFile(String content, String writePath, String charCoder)
  3. writeFile(String contents, File f)
  4. writeFile(String contents, File file)
  5. writeFile(String contents, String fileName)
  6. writeFile(String data, File file)
  7. writeFile(String data, File tar)
  8. writeFile(String datafile, String filePath)
  9. writeFile(String destination, byte[] data, boolean append)