Java FileInputStream Read readFile(File fyl)

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

Description

Read a file.

License

Open Source License

Parameter

Parameter Description
fyl the file to read from.

Exception

Parameter Description
FileNotFoundException , IOException if something goes wrong.

Return

the byte array contents of the file.

Declaration

public synchronized static byte[] readFile(File fyl) throws FileNotFoundException, IOException 

Method Source Code


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

import java.io.BufferedInputStream;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

import java.io.IOException;

public class Main {
    /**//  w  w  w  .  java 2s  .  c  om
     * Read a file.
     * @param fyl the file to read from.
     * @return the byte array contents of the file.
     * @throws FileNotFoundException, IOException if something goes wrong.
     */
    public synchronized static byte[] readFile(File fyl) throws FileNotFoundException, IOException {

        int len = (int) fyl.length();
        byte[] bfr = new byte[len];
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream(fyl));
        bis.read(bfr, 0, len);
        bis.close();

        return bfr;

    }
}

Related

  1. readFile(File file, int size)
  2. readFile(File file, OutputStream output)
  3. readFile(File file, String encoding)
  4. readFile(File file, String encoding)
  5. readFile(File file, String encoding)
  6. readFile(File path)
  7. readfile(File path)
  8. readFile(File source)
  9. readFile(File src)