Java Text File Load loadTextFile(String fileName)

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

Description

load Text File

License

Open Source License

Declaration

public static String loadTextFile(String fileName) throws Exception 

Method Source Code


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

import java.io.BufferedReader;

import java.io.FileReader;

public class Main {
    public static String loadTextFile(String fileName) throws Exception {
        BufferedReader br = new BufferedReader(new FileReader(fileName));
        String text = "";
        try {/*from  w w  w  .  jav  a  2  s.c o  m*/
            StringBuilder sb = new StringBuilder();
            String line = br.readLine();

            while (line != null) {
                sb.append(line);
                sb.append("\n");
                line = br.readLine();
            }
            text = sb.toString();
        } finally {
            br.close();
        }

        return text;
    }
}

Related

  1. loadTextFile(File file)
  2. loadTextFile(File textFile)
  3. loadTextFile(final String filePath)
  4. loadTextFile(String fileFullPath)
  5. loadTextFile(String fileName)
  6. loadTextFile(String filename)
  7. loadTextFile(String filename, int maxLines)
  8. loadTextFileAsLines(String fileName)