Java File Read getFileContent(final String fileName)

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

Description

get File Content

License

Open Source License

Declaration

public static StringBuilder getFileContent(final String fileName) 

Method Source Code

//package com.java2s;
/**// w ww  . ja  v a  2s .  co m
 * Copyright? 2014-2016 LIST (Luxembourg Institute of Science and Technology), all right reserved.
 * Authorship : Olivier PARISOT, Yoanne DIDRY
 * Licensed under GNU General Public License version 3
 */

import java.io.*;

public class Main {
    public static StringBuilder getFileContent(final String fileName) {
        final StringBuilder sb = new StringBuilder();

        BufferedReader br = null;
        try {
            final InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName);
            if (is == null)
                throw new Exception("File '" + fileName + "' not found!");
            br = new BufferedReader(new InputStreamReader(is, "ISO-8859-15"));
            String nextLine = "";
            while ((nextLine = br.readLine()) != null) {
                sb.append(nextLine);
                sb.append("\n");
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (br != null) {
                try {
                    br.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
        return sb;
    }
}

Related

  1. getFileContent(File file, int bufferSize)
  2. getFileContent(File pFile)
  3. getFileContent(final File f)
  4. getFileContent(final File file)
  5. getFileContent(final File srcFile)
  6. getFileContent(final String p_filename)
  7. getFileContentAsAString(final File aFile)
  8. getFileContentAsList(String filePath)
  9. getFileContentByLine(String filePath)