Java UTF File Write utf8Writer(final File f)

Here you can find the source of utf8Writer(final File f)

Description

Creates a Writer that writes to the given file, converting chars to bytes using the UTF-8 charset.

License

Open Source License

Parameter

Parameter Description
f file to write to

Exception

Parameter Description
IOException if the file couldn't be opened for writing

Return

Writer for the given file

Declaration

public static Writer utf8Writer(final File f) throws IOException 

Method Source Code


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

import java.io.File;

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

import java.io.OutputStreamWriter;

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

public class Main {
    /** UTF-8 charset instance. */
    public static final Charset UTF8 = Charset.forName("UTF-8");

    /**/*  ww w .j  a  va2  s .  c  o m*/
     * Creates a {@link Writer} that writes to the given file, converting chars
     * to bytes using the UTF-8 charset.
     * 
     * @param f
     *            file to write to
     * @return Writer for the given file
     * @throws IOException
     *             if the file couldn't be opened for writing
     */
    public static Writer utf8Writer(final File f) throws IOException {
        return new OutputStreamWriter(new FileOutputStream(f), UTF8);
    }
}

Related

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