Here you can find the source of getBufferedReaderMaybeGZ(String f)
Parameter | Description |
---|---|
filename | a parameter |
public static BufferedReader getBufferedReaderMaybeGZ(String f)
//package com.java2s; //License from project: Open Source License import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.InputStream; import java.io.InputStreamReader; import java.util.zip.GZIPInputStream; public class Main { /**//from w ww . j av a2 s .c o m * @param filename * @return the buffered reader for the file with filename. Accepts gzipped * and normal files, returning the gzipped file if and only if the normal * file doesn't exist (and the gzipped version does). */ public static BufferedReader getBufferedReaderMaybeGZ(String f) { /* * Moved here from machinereading/.../sri/util/FileMan. * This could be combined with getReaderFromGzippedFile (but make sure * it is backwards compatible with its original users). * - NLE 5/20/11 */ try { InputStream is; if (!new File(f).exists() && new File(f + ".gz").exists()) { f += ".gz"; // } FileInputStream fis = new FileInputStream(f); if (f.toLowerCase().endsWith(".gz")) { is = new GZIPInputStream(fis); } else { is = fis; } InputStreamReader reader = new InputStreamReader(is, "UTF8"); BufferedReader lreader = new BufferedReader(reader); return lreader; } catch (Exception e) { e.printStackTrace(); } return null; } }