Java OutputStreamWriter Write saveString(String string, File file, String charsetName)

Here you can find the source of saveString(String string, File file, String charsetName)

Description

save String

License

Open Source License

Declaration

public static void saveString(String string, File file, String charsetName) throws IOException 

Method Source Code


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

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

import java.io.OutputStream;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;

public class Main {
    public static void saveString(String string, File file, String charsetName) throws IOException {
        OutputStream out = new FileOutputStream(file);

        try {//from w ww.  j av a  2s  . c o  m
            saveString(string, out, charsetName);
        } finally {
            out.close();
        }
    }

    private static void saveString(String string, OutputStream stream, String charsetName) throws IOException {
        OutputStreamWriter out;
        if (charsetName == null) {
            out = new OutputStreamWriter(stream);
        } else {
            out = new OutputStreamWriter(stream, charsetName);
        }

        out.write(string, 0, string.length());
        out.flush();
    }
}

Related

  1. saveFile(String path, String msg)
  2. saveListString(List list, String filename)
  3. saveListText(String filename, List array)
  4. saveLongTxtList(long[] ids, String[] texts, String listFile)
  5. saveString(File f, String enc, String text)
  6. saveString2File(String s, String filename)
  7. saveStringToFile(String filename, String string)
  8. saveStringToFile(String toSave, String fn)
  9. saveStringToPath(String stringToSave, String pathToSaveTo)