Java Text File Read by Charset newReader(File file, Charset charset)

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

Description

new Reader

License

Apache License

Declaration

static BufferedReader newReader(File file, Charset charset) throws FileNotFoundException 

Method Source Code


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

import java.io.BufferedReader;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

import java.io.InputStreamReader;

import java.nio.charset.Charset;

import javax.annotation.Nullable;

public class Main {
    static BufferedReader newReader(File file, Charset charset) throws FileNotFoundException {
        checkNotNull(file);//from   w w w.  j av a2 s. c om
        checkNotNull(charset);
        return new BufferedReader(new InputStreamReader(new FileInputStream(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. inferCharset(byte[] bytes, int bytesRead, Charset clientCharset)
  2. initDecoder(Charset charset, ThreadLocal> localDecoder)
  3. inputStreamToString(InputStream input, Charset charset, boolean closeInputAfterRead)
  4. newBufferedFileReader(File file, Charset charset)
  5. newBufferedReader(URL url, Charset cs)
  6. newReader(InputStream input, Charset encoding)
  7. newReader(ReadableByteChannel ch, Charset cs)
  8. newUTF8CharSetReader(String filename)
  9. openNewCompressedInputReader(final InputStream inputStream, final Charset charset)