Java BufferedReader Read readFile(String fileName)

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

Description

read File

License

Open Source License

Declaration

static private String readFile(String fileName) throws IOException 

Method Source Code


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

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

public class Main {
    static private String readFile(String fileName) throws IOException {
        String everything = "";
        try (BufferedReader br = new BufferedReader(new FileReader(fileName))) {
            StringBuilder sb = new StringBuilder();
            String line = br.readLine();

            while (line != null) {
                sb.append(line);//w w  w  .j a  v a  2s .  c om
                sb.append(System.lineSeparator());
                line = br.readLine();
            }

            everything = sb.toString().substring(0, sb.length() - 2);
        } catch (IOException e) {
            throw e;
        }

        return everything;
    }
}

Related

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