Java OutputStreamWriter Write saveUnicodeStringToFile(final String string, final File file)

Here you can find the source of saveUnicodeStringToFile(final String string, final File file)

Description

Save unicode string to file.

License

Open Source License

Parameter

Parameter Description
string The Java string to write
file the file to write to

Exception

Parameter Description
IOException For any error

Declaration

public static void saveUnicodeStringToFile(final String string, final File file) throws IOException 

Method Source Code


//package com.java2s;

import java.io.BufferedWriter;
import java.io.File;

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

import java.io.OutputStreamWriter;

public class Main {
    /**//w  w  w  .java  2  s  .c  om
     * Save unicode string to file.
     * 
     * @param string The Java string to write
     * @param file the file to write to
     * @throws IOException For any error
     */
    public static void saveUnicodeStringToFile(final String string, final File file) throws IOException {
        final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF8"));
        bw.write(string);
        bw.flush();
        bw.close();
    }
}

Related

  1. saveStringToFile(String toSave, String fn)
  2. saveStringToPath(String stringToSave, String pathToSaveTo)
  3. saveText(BufferedWriter writer, String string)
  4. saveTextInFile(File file, String content, String encoding)
  5. saveTxt(OutputStream os, List list)
  6. saveUtfFileWithBOM(File file, String content)