Java OutputStreamWriter Write saveStringToFile(String filename, String string)

Here you can find the source of saveStringToFile(String filename, String string)

Description

save String To File

License

Open Source License

Declaration

public static boolean saveStringToFile(String filename, String string) 

Method Source Code

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

import java.io.BufferedWriter;

import java.io.FileOutputStream;
import java.io.IOException;

import java.io.OutputStreamWriter;

public class Main {

    public static boolean saveStringToFile(String filename, String string) {
        boolean saved = false;
        BufferedWriter bw = null;
        if (string == null || filename == null) {
            throw new NullPointerException("Null String");
        }//  w  ww . j  a  v a  2 s. c  o  m

        try {
            bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(filename), "UTF-8"));
            try {
                bw.write(string);
                saved = true;
            } finally {
                bw.close();
            }
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        return saved;
    }
}

Related

  1. saveListText(String filename, List array)
  2. saveLongTxtList(long[] ids, String[] texts, String listFile)
  3. saveString(File f, String enc, String text)
  4. saveString(String string, File file, String charsetName)
  5. saveString2File(String s, String filename)
  6. saveStringToFile(String toSave, String fn)
  7. saveStringToPath(String stringToSave, String pathToSaveTo)
  8. saveText(BufferedWriter writer, String string)
  9. saveTextInFile(File file, String content, String encoding)