Java UTF File Write getBufferedUTF8Writer(File file)

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

Description

Creates a BufferedWriter for UTF-8-encoded files

License

Creative Commons License

Parameter

Parameter Description
file File in UTF-8 encoding

Exception

Parameter Description
FileNotFoundException an exception

Return

BufferedWriter for file

Declaration

public static BufferedWriter getBufferedUTF8Writer(File file) throws FileNotFoundException 

Method Source Code

//package com.java2s;
/** /*from   w w w .j  av a2  s  .  c o m*/
This class is part of the Java Tools (see http://mpii.de/yago-naga/javatools).
It is licensed under the Creative Commons Attribution License 
(see http://creativecommons.org/licenses/by/3.0) by 
the YAGO-NAGA team (see http://mpii.de/yago-naga)
    
Some utility methods for arrays
*/

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

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

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

public class Main {
    /**
     * Creates a BufferedWriter for UTF-8-encoded files
     * 
     * @param file  File in UTF-8 encoding
     * @return      BufferedWriter for file
     * @throws FileNotFoundException
     */
    public static BufferedWriter getBufferedUTF8Writer(File file) throws FileNotFoundException {
        return new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), Charset.forName("UTF-8")));
    }

    /**
     * Creates a BufferedWriter for UTF-8-encoded files
     * 
     * @param fileName  Path to file in UTF-8 encoding
     * @return      BufferedWriter for file
     * @throws FileNotFoundException
     */
    public static BufferedWriter getBufferedUTF8Writer(String fileName) throws FileNotFoundException {
        return new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName), Charset.forName("UTF-8")));
    }
}

Related

  1. asPrintWriterUTF8(OutputStream out)
  2. getUTF8FileAppendWriter(String filename)
  3. getUTF8FileWriter(File f)
  4. getUTF8Writer(OutputStream os)
  5. getUTF8Writer(String file)