Java FileReader Read readFile(String filename)

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

Description

read File

License

LGPL

Declaration

public static String readFile(String filename) throws IOException 

Method Source Code


//package com.java2s;
//License from project: LGPL 

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

public class Main {
    public static String readFile(String filename) throws IOException {
        String content = null;/*from w  w  w. j a v a 2  s.c o m*/
        File file = new File(filename);
        FileReader reader = null;
        try {
            reader = new FileReader(file);
            char[] chars = new char[(int) file.length()];
            reader.read(chars);
            content = new String(chars);
            reader.close();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (reader != null) {
                reader.close();
            }
        }
        return content;
    }
}

Related

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