Java FileInputStream 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.*;

public class Main {
    public static String readFile(File file) throws IOException {
        FileInputStream fstream = null;
        try {//from   w ww  .  j a v  a 2s.c  o m
            fstream = new FileInputStream(file);
            byte[] bytes = new byte[(int) file.length()];
            fstream.read(bytes);
            fstream.close();
            return new String(bytes);
        } catch (Exception e) {
            throw new IOException(e);
        } finally {
            quiteClose(fstream);
        }
    }

    public static void quiteClose(Closeable stream) {
        try {
            if (stream != null) {
                stream.close();
            }
        } catch (IOException e) {
            /* Ignore */
        }
    }
}

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)