Java InputStreamReader Create readTextFile(File fromFile)

Here you can find the source of readTextFile(File fromFile)

Description

Read the String content from File.

License

Open Source License

Parameter

Parameter Description
fromFile a parameter

Exception

Parameter Description
IOException an exception

Declaration

public static String readTextFile(File fromFile) throws IOException 

Method Source Code

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

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;

import java.io.IOException;

import java.io.InputStreamReader;

public class Main {
    /**/*from   ww w  .ja  va 2 s  . c o  m*/
     * Read the String content from File. 
     * @param fromFile
     * @return
     * @throws IOException
     */
    public static String readTextFile(File fromFile) throws IOException {
        StringBuffer buf = new StringBuffer();
        BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(fromFile)));
        String inputLine;
        while ((inputLine = in.readLine()) != null) {
            buf.append(inputLine);
            buf.append('\n');
        }

        in.close();
        return buf.toString();
    }
}

Related

  1. readTextFile(File f)
  2. readTextFile(File f, int maxNumLines)
  3. readTextFile(File file)
  4. readTextFile(File file)
  5. readTextFile(File file, String charsetName)
  6. readTextFile(File inputFile)
  7. readTextFile(File path)
  8. readTextFile(final File f)
  9. readTextFile(final File file)