Here you can find the source of getBufferedReaderFromFileName(File file)
Parameter | Description |
---|---|
path | Path to the file to be opened |
isGzip | whether or not the file is gzip-compressed |
Parameter | Description |
---|---|
IOException | on I/O errors |
public static BufferedReader getBufferedReaderFromFileName(File file) throws IOException
//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; } }