Java FileInputStream Read readFile(File file)

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

Description

Reads a file in binary format

License

Open Source License

Parameter

Parameter Description
file a parameter

Declaration

public static byte[] readFile(File file) 

Method Source Code

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

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

import java.io.IOException;

public class Main {
    /**/*w  w w.  j a v  a2 s.co m*/
     * Reads a file in binary format
     * 
     * @param file
     * @return
     */
    public static byte[] readFile(File file) {
        byte[] b = new byte[(int) file.length()];
        try {
            FileInputStream fs = new FileInputStream(file);
            fs.read(b);
            //         for (int i = 0; i < b.length; i++) {
            //            System.out.print((char) b[i]);
            //         }
            fs.close();
        } catch (FileNotFoundException e) {
            System.out.println("File Not Found.");
            e.printStackTrace();
        } catch (IOException e1) {
            System.out.println("Error Reading The File.");
            e1.printStackTrace();
        }

        return b;
    }
}

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)