Java InputStreamReader Read readFile(String aFile)

Here you can find the source of readFile(String aFile)

Description

Read a file into a string

License

Open Source License

Parameter

Parameter Description
aFile aFile

Return

file into a string

Declaration

public static String readFile(String aFile) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;

public class Main {
    /**/*  ww w  . j ava2 s .c o m*/
     * Read a file into a string
     * 
     * @param aFile aFile
     * @return file into a string
     */
    public static String readFile(String aFile) {
        BufferedReader bin = null;
        StringBuilder sb = new StringBuilder();
        try {
            FileInputStream is = new FileInputStream(aFile);
            bin = new BufferedReader(new InputStreamReader(is, "UTF-8"));

            String line = null;
            while ((line = bin.readLine()) != null) {
                sb.append(line);
                sb.append(System.getProperty("line.separator"));
            }

            bin.close();

        } catch (Exception e) {
            e.printStackTrace();
            System.exit(-1);
        }

        return sb.toString();
    }
}

Related

  1. readFile(InputStream inputStream)
  2. readFile(InputStream is)
  3. readFile(InputStream location)
  4. readFile(InputStream stream, StringBuilder builder)
  5. readFile(Reader simpleReader)
  6. readFile(String f)
  7. readFile(String f, String delim)
  8. readFile(String file)
  9. readFile(String file)