Java FileReader 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.FileNotFoundException;

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

import java.io.LineNumberReader;

public class Main {

    public static String readFile(String filename) {
        String return_str = "";
        try {/*from w  ww  .  j a v a 2 s .c o m*/
            FileReader fr = new FileReader(filename);
            LineNumberReader lr = new LineNumberReader(fr, 512);
            while (true) {
                String str = lr.readLine();
                if (str == null)
                    break;
                return_str += str + "\n";
            }
            lr.close();
        } catch (FileNotFoundException e) {
            System.out.println("FILENAME:" + filename);
            System.out.println("File not found");
            // return_str="error1!";
        } catch (IOException e) {
            System.out.println("IO error");
            // return_str="error2!";
        }
        return return_str;
    }
}

Related

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