Java FileReader Create readTextFile(String fileName)

Here you can find the source of readTextFile(String fileName)

Description

read Text File

License

Open Source License

Declaration

public static String readTextFile(String fileName) 

Method Source Code


//package com.java2s;
import java.io.*;

public class Main {
    public static String readTextFile(String fileName) {
        try {//from   ww  w. j  a v a 2s  .c om
            BufferedReader in = new BufferedReader(new FileReader(fileName));
            String line, fileContents;

            fileContents = null;

            while ((line = in.readLine()) != null) {
                if (fileContents == null)
                    fileContents = line + "\n";
                else
                    fileContents = fileContents + line + "\n";
            }
            in.close();
            return fileContents;
        } catch (Exception e) {
            return e.getMessage();
        }
    }
}

Related

  1. readTextFile(String file)
  2. readTextFile(String filename)
  3. readTextFile(String filename)
  4. readTextFile(String fileName)
  5. readTextFile(String filename)
  6. readTextFile(String fileName)
  7. readTextFile(String fileName)
  8. readTextFile(String fileName)
  9. readTextFile(String filename)