Java UTF File Write utf8Writer(File file)

Here you can find the source of utf8Writer(File file)

Description

Creates a writer whose character encoding is set to "UTF-8".

License

Open Source License

Parameter

Parameter Description
file the file to write to

Exception

Parameter Description
FileNotFoundException if the file cannot be written to

Return

the writer

Declaration

public static Writer utf8Writer(File file) throws FileNotFoundException 

Method Source Code

//package com.java2s;

import java.io.File;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;

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

import java.io.Writer;
import java.nio.charset.Charset;

public class Main {
    private static final Charset UTF8 = Charset.forName("UTF-8");

    /**/*ww  w. ja  v a 2s.c  om*/
     * Creates a writer whose character encoding is set to "UTF-8".
     * @param out the output stream to write to
     * @return the writer
     */
    public static Writer utf8Writer(OutputStream out) {
        return new OutputStreamWriter(out, UTF8);
    }

    /**
     * Creates a writer whose character encoding is set to "UTF-8".
     * @param file the file to write to
     * @return the writer
     * @throws FileNotFoundException if the file cannot be written to
     */
    public static Writer utf8Writer(File file) throws FileNotFoundException {
        return utf8Writer(file, false);
    }

    /**
     * Creates a writer whose character encoding is set to "UTF-8".
     * @param file the file to write to
     * @param append true to append to the end of the file, false to overwrite
     * it
     * @return the writer
     * @throws FileNotFoundException if the file cannot be written to
     */
    public static Writer utf8Writer(File file, boolean append) throws FileNotFoundException {
        return utf8Writer(new FileOutputStream(file, append));
    }
}

Related

  1. getBufferedUTF8Writer(File file)
  2. getUTF8FileAppendWriter(String filename)
  3. getUTF8FileWriter(File f)
  4. getUTF8Writer(OutputStream os)
  5. getUTF8Writer(String file)
  6. utf8Writer(final File f)
  7. writeFile(byte[] data, String outfile)
  8. writeFile(String fileName, ArrayList data, String outputFolder)
  9. writeFileUTF(String nom)