Java File to Byte Array fileToByteArray(final File f)

Here you can find the source of fileToByteArray(final File f)

Description

file To Byte Array

License

Open Source License

Declaration

public static byte[] fileToByteArray(final File f) throws IOException 

Method Source Code

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

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

import java.io.IOException;

public class Main {
    public static byte[] fileToByteArray(final File f) throws IOException {
        final FileInputStream is = new FileInputStream(f);
        final byte[] ret = new byte[(int) f.length()];
        int p = 0;
        while (p < ret.length)
            p += is.read(ret, p, ret.length - p);
        is.close();//from  w  w w. j  ava  2 s.c o m
        return ret;
    }
}

Related

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