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) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

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

public class Main {
    public static void writeStringToFile(String fileName, String content) {

        FileWriter fileWriter = null;

        try {//from  www  .j  a v  a 2  s  .c  om
            File newTextFile = new File(fileName);
            fileWriter = new FileWriter(newTextFile);
            fileWriter.write(content);
            fileWriter.close();
        } catch (IOException ex) {
            throw new RuntimeException(ex);

        } finally {
            try {
                fileWriter.close();
            } catch (IOException ex) {
                throw new RuntimeException(ex);
            }
        }
    }
}

Related

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