Java Text File Write by Charset newWriter(File file, Charset charset)

Here you can find the source of newWriter(File file, Charset charset)

Description

new Writer

License

Apache License

Declaration

static BufferedWriter newWriter(File file, Charset charset) throws FileNotFoundException 

Method Source Code

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

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;

import javax.annotation.Nullable;

public class Main {
    static BufferedWriter newWriter(File file, Charset charset) throws FileNotFoundException {
        checkNotNull(file);//from   w ww  .jav  a2  s  . c o  m
        checkNotNull(charset);
        return new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), charset));
    }

    static <T> T checkNotNull(T reference, @Nullable Object errorMessage) {
        if (reference == null) {
            throw new NullPointerException(String.valueOf(errorMessage));
        }
        return reference;
    }

    static <T> T checkNotNull(T reference) {
        if (reference == null) {
            throw new NullPointerException();
        }
        return reference;
    }
}

Related

  1. getWriter(OutputStream os, String charset)
  2. getWriter(OutputStream out, String charsetName)
  3. getWriter(String fileName, Charset cs)
  4. getWriter(String path, Charset encoding)
  5. newFilePrintWriter(File file, Charset charset)
  6. newWriter(OutputStream output, Charset encoding)
  7. newWriter(WritableByteChannel ch, Charset cs)
  8. openTextFileForWriting(File f, Charset encoding)
  9. openWriter(OutputStream stream, Charset charset, boolean autoflush)