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

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

Description

write File

License

Open Source License

Declaration

public static void writeFile(String filename, String text) 

Method Source Code

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

import java.io.BufferedWriter;
import java.io.Closeable;

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

public class Main {

    public static void writeFile(String filename, String text) {
        try {/*from w ww . j a  va2  s  .c om*/
            // Create file
            FileWriter fstream = new FileWriter(filename);
            BufferedWriter out = new BufferedWriter(fstream);
            out.write(text);
            // Close the output stream
            out.close();
        } catch (Exception e) {// Catch exception if any
            System.err.println("Error: " + e.getMessage());
        }
    }

    public static void close(Closeable closeable) {
        try {
            closeable.close();
        } catch (IOException ignored) {
        }
    }
}

Related

  1. writeFile(String fileName, String source)
  2. writeFile(String filename, String str)
  3. writeFile(String filename, String string)
  4. writeFile(String filename, String text)
  5. writeFile(String filename, String text)
  6. writeFile(String fileName, String text)
  7. writeFile(String filename, String text, boolean create)
  8. writeFile(String fileName, String text, String characterEncoding)
  9. writeFile(String fileName, String textToSave)