Java BufferedReader Create getReader(String filename)

Here you can find the source of getReader(String filename)

Description

get Reader

License

Open Source License

Declaration

public static BufferedReader getReader(String filename) 

Method Source Code

//package com.java2s;
// This software is released under the 2-clause BSD license.

import java.io.*;
import java.util.zip.*;

public class Main {
    public static final String DEFAULT_ENCODING = "UTF-8";

    public static BufferedReader getReader(String filename) {
        return getReader(filename, "UTF-8");
    }/*from   ww  w  .  j  ava  2  s. c  om*/

    public static BufferedReader getReader(String filename, String encoding) {
        return getReader(new File(filename), encoding);
    }

    public static BufferedReader getReader(File input) {
        return getReader(input, DEFAULT_ENCODING);
    }

    public static BufferedReader getReader(File input, String encoding) {
        try {
            InputStream is = new FileInputStream(input);
            if (input.getName().endsWith(".gz"))
                is = new GZIPInputStream(is);
            return new BufferedReader(new InputStreamReader(is, encoding));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}

Related

  1. getReader(InputStream is)
  2. getReader(InputStream is)
  3. getReader(String fileDir, String fileName, String encoding)
  4. getReader(String filename)
  5. getReader(String filename)
  6. getReader(String filePath, String charset)
  7. getReader(String path)
  8. getReader(String Path)
  9. getReader(String path, String charEncoding)