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

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

Description

write String To File

License

Open Source License

Declaration

public static void writeStringToFile(String filename, String text) 

Method Source Code


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

import java.io.FileOutputStream;
import java.io.PrintStream;

public class Main {
    public static void writeStringToFile(String filename, String text) {
        FileOutputStream stream = null;
        PrintStream out = null;// w  w w.ja  va  2 s. c om
        try {

            stream = new FileOutputStream(filename);
            out = new PrintStream(stream);
            out.print(text);
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            try {
                if (stream != null)
                    stream.close();
                if (out != null)
                    out.close();
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    }
}

Related

  1. writeStringToFile(String filename, String str)
  2. writeStringToFile(String fileName, String str, boolean isAppend)
  3. writeStringToFile(String filename, String string)
  4. writeStringToFile(String filename, String string, boolean overwrite)
  5. writeStringToFile(String filename, String stringToWrite)
  6. WriteStringToFile(String fn, String dest)
  7. writeStringToFile(String fullPath, byte[] fileBytes)
  8. writeStringToFile(String fullPath, String content)
  9. writeStringToFile(String jsonStr, File file)