Java BufferedReader Read readFile(String fileName)

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

Description

Read the file and wirte the contents into the

License

Open Source License

Declaration

public static String readFile(String fileName) 

Method Source Code

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

import java.io.BufferedReader;

import java.io.FileReader;

public class Main {
    /**//w w  w .java  2  s . c  o m
     * Read the file and wirte the contents into the
     */
    public static String readFile(String fileName) {
        BufferedReader bufferedReader = null;
        FileReader fileReader = null;
        String string = "";
        try {
            fileReader = new FileReader(fileName);
            bufferedReader = new BufferedReader(fileReader);

            String temp = null;
            string = "";
            temp = bufferedReader.readLine();
            while (temp != null) {
                string += temp + "\r\n";
                temp = bufferedReader.readLine();
            }

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if (bufferedReader != null) {
                    bufferedReader.close();
                }
                if (fileReader != null) {
                    fileReader.close();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return string;
    }
}

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)