Java FileReader Create readTextFile(String file)

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

Description

read Text File

License

Open Source License

Declaration

public static String readTextFile(String file) throws Exception 

Method Source Code


//package com.java2s;
//    it under the terms of the GNU General Public License as published by

import java.io.BufferedReader;

import java.io.FileReader;

public class Main {
    public static String readTextFile(String file) throws Exception {
        String everything;/*from   www  .ja  v  a  2  s. c o  m*/

        try (BufferedReader br = new BufferedReader(new FileReader(file))) {
            StringBuilder sb = new StringBuilder();
            String line = br.readLine();

            while (line != null) {
                sb.append(line);
                sb.append(System.lineSeparator());
                line = br.readLine();
            }
            everything = sb.toString();
        }
        return everything;
    }
}

Related

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