Java UTF File Write asPrintWriterUTF8(OutputStream out)

Here you can find the source of asPrintWriterUTF8(OutputStream out)

Description

Create a print writer that uses UTF-8 encoding

License

Open Source License

Declaration

static public PrintWriter asPrintWriterUTF8(OutputStream out) 

Method Source Code

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

import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;

import java.io.Reader;

import java.io.Writer;

import java.nio.charset.Charset;

public class Main {
    static Charset utf8 = null;

    /** Create a print writer that uses UTF-8 encoding */
    static public PrintWriter asPrintWriterUTF8(OutputStream out) {
        return new PrintWriter(asUTF8(out));
    }//from  w w w . j a  va 2  s .c o  m

    /** Create a reader that uses UTF-8 encoding */
    static public Reader asUTF8(InputStream in) {
        return new InputStreamReader(in, utf8.newDecoder());
    }

    /** Create a writer that uses UTF-8 encoding */
    static public Writer asUTF8(OutputStream out) {
        return new OutputStreamWriter(out, utf8.newEncoder());
    }
}

Related

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