Java InputStreamReader Read readFile(String fileName, Class clazz)

Here you can find the source of readFile(String fileName, Class clazz)

Description

read File

License

BSD License

Declaration

public static String readFile(String fileName, Class<?> clazz) 

Method Source Code


//package com.java2s;
//License from project: BSD License 

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static String readFile(String fileName, Class<?> clazz) {
        StringBuilder sb = new StringBuilder();
        BufferedReader br = null;
        try {// w w  w .  j  a  va2 s  . c  o  m
            br = new BufferedReader(new InputStreamReader(clazz.getResourceAsStream(fileName)));
            String line;
            while ((line = br.readLine()) != null) {
                sb.append(line + "\n");
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (br != null) {
                    br.close();
                }

            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return sb.toString();
    }
}

Related

  1. readFile(String fileName)
  2. readFile(String fileName)
  3. readFile(String fileName)
  4. readfile(String filename)
  5. readFile(String filename, boolean addEOL)
  6. readFile(String fileName, String characterEncoding)
  7. readFile(String fileName, String characterEncoding)
  8. readFile(String fileName, String characterEncoding)
  9. readFile(String fileName, String charSet)