Java BufferedReader Create getReader(final String fileName)

Here you can find the source of getReader(final String fileName)

Description

Get input reader to given file.

License

BSD License

Parameter

Parameter Description
fileName File name

Return

Reader

Declaration

public static BufferedReader getReader(final String fileName) 

Method Source Code


//package com.java2s;
/*L/*from w ww.java 2s.  c  om*/
 *  Copyright RTI International
 *
 *  Distributed under the OSI-approved BSD 3-Clause License.
 *  See http://ncip.github.com/webgenome/LICENSE.txt for details.
 */

import java.io.BufferedReader;

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

public class Main {
    /**
     * Get input reader to given file.
     * @param fileName File name
     * @return Reader
     */
    public static BufferedReader getReader(final String fileName) {
        InputStream stream = getInputStream(fileName);
        BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
        return reader;
    }

    /**
     * Get input stream for specified file name.
     * @param fileName Relative file name (not full path)
     * @return An input stream
     */
    public static InputStream getInputStream(final String fileName) {
        Thread curThread = Thread.currentThread();
        ClassLoader loader = curThread.getContextClassLoader();
        return loader.getResourceAsStream(fileName);
    }
}

Related

  1. getReader(File queryFile)
  2. getReader(final File inputFile)
  3. getReader(final InputStream is, final String enc)
  4. getReader(final Object aReference, final String aResourceName)
  5. getReader(final String fileName)
  6. getReader(InputStream in)
  7. getReader(InputStream input)
  8. getReader(InputStream is)
  9. getReader(InputStream is)