Java File to Byte Array FiletoByteArray(File file)

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

Description

File to ByteArray

License

Open Source License

Parameter

Parameter Description
file File to Read

Return

File's Buffer

Declaration

public final static byte[] FiletoByteArray(File file) 

Method Source Code

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

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

public class Main {
    /**/*from   www .  j  ava 2s .c om*/
     * File to ByteArray
     * @param file File to Read
     * @return File's Buffer
     * @author Blue Electric
     */
    public final static byte[] FiletoByteArray(File file) {
        try {
            FileInputStream fis = new FileInputStream(file);
            byte[] result = new byte[fis.available()];
            fis.read(result);
            fis.close();
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
}

Related

  1. fileToByteArray(File file)
  2. fileToByteArray(File file)
  3. fileToByteArray(File file)
  4. fileToByteArray(File file)
  5. fileToByteArray(final File f)
  6. fileToByteArray(final IFile file)
  7. fileToByteArray(String filePath)
  8. fileToByteArray(String fname)