Java Text File Write writeStringToFile(String filename, String content)

Here you can find the source of writeStringToFile(String filename, String content)

Description

write String To File

License

Open Source License

Declaration

public static void writeStringToFile(String filename, String content) throws FileNotFoundException 

Method Source Code

//package com.java2s;
/*/*from  w ww.j  a  va 2s.com*/
 *  Copyright (c) Ludger Solbach. All rights reserved.
 *  The use and distribution terms for this software are covered by the
 *  Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
 *  which can be found in the file license.txt at the root of this distribution.
 *  By using this software in any fashion, you are agreeing to be bound by
 *  the terms of this license.
 *  You must not remove this notice, or any other, from this software.
 */

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;

import java.io.PrintWriter;

public class Main {
    public static void writeStringToFile(String filename, String content) throws FileNotFoundException {
        File file = new File(filename);
        PrintWriter pw = new PrintWriter(new FileOutputStream(file));
        pw.print(content);
        pw.close();
    }

    public static void writeStringToFile(File file, String content) throws FileNotFoundException {
        PrintWriter pw = new PrintWriter(new FileOutputStream(file));
        pw.print(content);
        pw.close();
    }
}

Related

  1. writeStringToFile(String data, String filepath)
  2. writeStringToFile(String f, String s, boolean append)
  3. writeStringToFile(String file, String data, boolean append)
  4. writeStringToFile(String file, String str, boolean append, boolean newLine)
  5. writeStringToFile(String fileName, String content)
  6. writeStringToFile(String fileName, String src)
  7. writeStringToFile(String filename, String str)
  8. writeStringToFile(String fileName, String str, boolean isAppend)
  9. writeStringToFile(String filename, String string)