Java BufferedReader Create getBufferedReaderFromFileName(File file)

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

Description

Open a file handle from a gzip-compressed or uncompressed file

License

Creative Commons License

Parameter

Parameter Description
path Path to the file to be opened
isGzip whether or not the file is gzip-compressed

Exception

Parameter Description
IOException on I/O errors

Return

Corresponding BufferedReader file handle.

Declaration

public static BufferedReader getBufferedReaderFromFileName(File file) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Creative Commons License 

import java.io.BufferedReader;

import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;

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

import java.util.zip.GZIPInputStream;

public class Main {
    /**//  ww w  .  j ava  2 s  .com
     * Open a file handle from a gzip-compressed or uncompressed file
     *
     * @param path
     *            Path to the file to be opened
     * @param isGzip
     *            whether or not the file is gzip-compressed
     * @return Corresponding BufferedReader file handle.
     * @throws IOException
     *             on I/O errors
     */
    public static BufferedReader getBufferedReaderFromFileName(File file) throws IOException {
        FileInputStream fin = new FileInputStream(file);
        BufferedReader br;
        if (file.getName().endsWith(".gz"))
            br = new BufferedReader(new InputStreamReader(new GZIPInputStream(fin)));
        else
            br = new BufferedReader(new InputStreamReader(new DataInputStream(fin)));
        return br;
    }
}

Related

  1. getBufferedReader(String filename)
  2. getBufferedReader(String filename, String encoding)
  3. getBufferedReader(String nombreFichero)
  4. getBufferedReader(String szFile)
  5. getBufferedReaderAsResource(Class clazz, String fileName)
  6. getBufferedReaderFromInputStream(InputStream src)
  7. getBufferedReaderFromInputStreamReader(InputStreamReader isReader)
  8. getBufferedReaderMaybeGZ(String f)
  9. getReader()