Java BufferedReader Read loadReaderFromClasspath(Class c, String filename)

Here you can find the source of loadReaderFromClasspath(Class c, String filename)

Description

"Transform" a file on the classpath into a BufferedReader

License

Open Source License

Parameter

Parameter Description
filename a parameter

Declaration

public static BufferedReader loadReaderFromClasspath(Class c, String filename) 

Method Source Code


//package com.java2s;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;

import java.io.InputStreamReader;

public class Main {
    /**//from   ww w.  j  a  va2s. c om
     * "Transform" a file on the classpath into a BufferedReader
     * 
     * @param filename
     * @return
     */
    public static BufferedReader loadReaderFromClasspath(Class c, String filename) {
        return new BufferedReader(new InputStreamReader(c.getClassLoader().getResourceAsStream(filename)));
    }

    /**
     * "Transform" a file on the classpath into a BufferedReader
     * 
     * @param filename
     * @return
     */
    public static BufferedReader loadReaderFromClasspath(String filename) {
        try {
            return new BufferedReader(new FileReader(new File(filename)));
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return null;
    }
}

Related

  1. loadPartitions(String fileName)
  2. loadPathPreferencesFromFile(File inputFile)
  3. loadPrivateKeyFile(File privateKeyFile)
  4. loadQueryFromFile(String queryFile)
  5. loadQueryNodeInfo(String input_file)
  6. loadReaderToList(Reader reader)
  7. loadRealDataGraphFromEmbers(String fileName, String splitter)
  8. loadSentences(InputStream stream, List jsonSentences)
  9. loadSimpleTextFile(File file, int bufferSize)