Java Text File Write by Charset getWriter(String fileName, Charset cs)

Here you can find the source of getWriter(String fileName, Charset cs)

Description

get Writer

License

Apache License

Declaration

public static Writer getWriter(String fileName, Charset cs) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

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

import java.io.OutputStreamWriter;

import java.io.Writer;

import java.nio.charset.Charset;

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

    public static Writer getWriter(String fileName, Charset cs) {
        OutputStreamWriter writer = null;
        try {//from  w  w w . j  a va2  s  . c om
            return new OutputStreamWriter(new FileOutputStream(fileName), cs);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        return writer;
    }

    public static Writer getWriter(String fileName) {
        return getWriter(fileName, defaultCharset);
    }
}

Related

  1. copy(byte[] input, Writer output, Charset charset)
  2. createWriter(@Nullable final OutputStream aOS, @Nonnull final Charset aCharset)
  3. createWriter(@Nullable final OutputStream aOS, @Nonnull final String sCharset)
  4. getWriter(OutputStream os, String charset)
  5. getWriter(OutputStream out, String charsetName)
  6. getWriter(String path, Charset encoding)
  7. newFilePrintWriter(File file, Charset charset)
  8. newWriter(File file, Charset charset)
  9. newWriter(OutputStream output, Charset encoding)