Java File to Reader openReader(String file)

Here you can find the source of openReader(String file)

Description

Create a newBufferedReader

License

Open Source License

Parameter

Parameter Description
fileName the name of the file we want to open for reading

Return

a reader to a given file

Declaration

static protected BufferedReader openReader(String file) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2006 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:/*from w  ww .  j  a  v a  2s  .c om*/
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

import java.io.BufferedReader;

import java.io.File;
import java.io.FileReader;

public class Main {
    /**
     * Create a newBufferedReader
     * 
     * @param fileName
     *            the name of the file we want to open for reading
     * 
     * @return a reader to a given file
     */
    static protected BufferedReader openReader(String file) {

        try {

            File f = new File(file);

            if (f.exists() == false) {
                return null;
            }

            return new BufferedReader(new FileReader(file));

        } catch (Exception e) {
            e.printStackTrace();
        }

        return null;
    }
}

Related

  1. newReader(File pathname)
  2. newReader(String value)
  3. openReader(File file)
  4. openReader(final String file, String charset)
  5. openReader(String dir, String filename, String encoding)
  6. openReader(String filePath)
  7. openReader(String fname)