Java Text File Read by Charset createReader(Path p, Charset cs)

Here you can find the source of createReader(Path p, Charset cs)

Description

create Reader

License

Open Source License

Declaration

public static Reader createReader(Path p, Charset cs)
            throws IOException 

Method Source Code

//package com.java2s;
/*/*from ww w . jav a2 s .  co  m*/
 * Copyright 2012-2015 Johns Hopkins University HLTCOE. All rights reserved.
 * See LICENSE in the project root directory.
 */

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;

import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;

import java.util.zip.GZIPInputStream;

public class Main {
    public static Reader createReader(Path p, Charset cs)
            throws IOException {
        InputStream is = Files.newInputStream(p);
        InputStream gis;
        if (p.toString().endsWith(".gz"))
            gis = new GZIPInputStream(is);
        else
            gis = is;
        Reader r = new InputStreamReader(gis, cs);
        return r;
    }

    public static Reader createReader(Path p) throws IOException {
        return createReader(p, StandardCharsets.UTF_8);
    }
}

Related

  1. convert(File file, Charset from, String toEncoding, ByteArrayOutputStream bytearray, boolean headersOn, int totalLinesToRead)
  2. copy(Reader input, OutputStream output, Charset encoding)
  3. createBOMStrippedReader(InputStream stream, String defaultCharset)
  4. createBufferedReaderWithGuessedCharset(File file)
  5. createInputStreamReader(File file, String charsetName)
  6. getDecoder(Charset charset, ThreadLocal> localDecoder)
  7. getFileContent(IFile file, String charset)
  8. getInputStreamReader(InputStream stream, Charset charset)
  9. getReader(InputStream in, String charsetName)