Java FileReader Read readFile(File file)

Here you can find the source of readFile(File file)

Description

read File

License

Open Source License

Declaration

public static String readFile(File file) throws IOException 

Method Source Code

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

import java.io.File;

import java.io.FileReader;

import java.io.IOException;

public class Main {
    public static String readFile(File file) throws IOException {

        FileReader a = null;/* ww  w .j a va 2s .c  o  m*/
        char[] d = null;
        try {
            a = new FileReader(file);
            int b;
            int c = 0;
            char[] e = null;
            b = a.read();
            while (b >= 0) {
                e = new char[c + 1];
                if (d != null) {
                    System.arraycopy(d, 0, e, 0, d.length);
                } else {
                    d = new char[1];
                }
                e[c] = (char) b;
                d = e.clone();
                c++;
                b = a.read();
            }
        } finally {
            if (a != null) {
                a.close();
            }
        }
        if (d != null) {
            return String.copyValueOf(d);
        } else {
            return "";
        }
    }
}

Related

  1. readFile(File file)
  2. readFile(File file)
  3. readFile(File file)
  4. readFile(File file)
  5. readFile(File file)
  6. readFile(File file)
  7. readFile(File file)
  8. readFile(File file)
  9. readFile(File file)