Java BufferedReader Read readFile(String fileName)

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

Description

read File

License

Open Source License

Declaration

public static String readFile(String fileName) 

Method Source Code


//package com.java2s;

import java.io.BufferedReader;

import java.io.File;

import java.io.FileNotFoundException;

import java.io.FileReader;

import java.io.IOException;

public class Main {
    private final static String NEW_LINE = System.getProperty("line.separator");

    public static String readFile(String fileName) {
        String retStr = "";
        File f = new File(fileName);
        try {//from   ww  w.ja v a2  s.c o m
            BufferedReader br = new BufferedReader(new FileReader(f));
            StringBuffer buff = new StringBuffer();
            String line = br.readLine();
            while (line != null) {
                buff.append(line + NEW_LINE);
                line = br.readLine();
            }
            retStr = buff.toString();
            br.close();
        } catch (FileNotFoundException e1) {
            e1.printStackTrace();
        } catch (IOException e1) {
            e1.printStackTrace();
        }
        return retStr;
    }
}

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)