Java BufferedReader Create getReader(File file)

Here you can find the source of getReader(File file)

Description

Returns a buffered reader for a file.

License

LGPL

Parameter

Parameter Description
file -- the input file

Exception

Parameter Description
IOException an exception

Return

BufferedReader for file

Declaration

public static BufferedReader getReader(File file) throws IOException 

Method Source Code


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

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;

import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;

import java.util.zip.GZIPInputStream;

public class Main {
    /**//from w  ww .  j ava 2 s.  co  m
     * Returns a buffered reader for a file.
     * Similar to the getPrintWriter() method gzip compression is supported. 
     * @param file -- the input file
     * @return BufferedReader for file
     * @throws IOException
     */
    public static BufferedReader getReader(File file) throws IOException {
        if (file.getName().endsWith(".gz")) {
            return new BufferedReader(new InputStreamReader(new GZIPInputStream(new FileInputStream(file))));
        }
        return new BufferedReader(new FileReader(file));
    }
}

Related

  1. getBufferedReaderFromInputStreamReader(InputStreamReader isReader)
  2. getBufferedReaderMaybeGZ(String f)
  3. getReader()
  4. getReader(File file)
  5. getReader(File file)
  6. getReader(File file)
  7. getReader(File inFile)
  8. getReader(File queryFile)
  9. getReader(final File inputFile)