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;
/* /*from  w ww . jav  a 2s.  co  m*/
    
 Created on Mar 4, 2005
    
 The Bungee View applet lets you search, browse, and data-mine an image collection.  
 Copyright (C) 2006  Mark Derthick
    
 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 as published by the Free Software Foundation; either version 2
 of the License, or (at your option) any later version.  See gpl.html.
    
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
    
 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    
 You may also contact the author at 
 mad@cs.cmu.edu, 
 or at
 Mark Derthick
 Carnegie-Mellon University
 Human-Computer Interaction Institute
 Pittsburgh, PA 15213
    
 */

import java.io.BufferedReader;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

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

import java.io.PrintWriter;
import java.io.StringWriter;

import java.util.zip.GZIPInputStream;

public class Main {
    public static BufferedReader getReader(String filename) {
        return getReader(new File(filename));
    }

    public static BufferedReader getReader(File file) {
        BufferedReader in = null;
        try {
            InputStream inputStream = new FileInputStream(file);
            if (file.getName().endsWith(".gz"))
                inputStream = new GZIPInputStream(inputStream);
            in = new BufferedReader(new InputStreamReader(inputStream));
        } catch (FileNotFoundException e) {
            System.err.println("Can't find file " + file);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return in;
    }

    public static String printStackTrace() {
        (new RuntimeException("Relax.  There's no error, we're just printing the stack trace")).printStackTrace();
        return null;
    }

    public static String printStackTrace(Throwable e) {
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        e.printStackTrace(pw);
        return sw.toString();
    }
}

Related

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