Java File to Byte Array fileToByteArray(File file)

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

Description

file To Byte Array

License

Open Source License

Declaration

public static byte[] fileToByteArray(File file) throws IOException 

Method Source Code

//package com.java2s;
/**/*from www .  j  a v a2 s  . c om*/
 * Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.com
 *
 * The software in this package is published under the terms of the CPAL v1.0
 * license, a copy of which has been included with this distribution in the
 * LICENSE.md file.
 */

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

public class Main {
    public static byte[] fileToByteArray(File file) throws IOException {
        byte[] byteArray = new byte[(int) file.length()];
        InputStream fis = new FileInputStream(file);
        fis.read(byteArray);
        fis.close();
        return byteArray;
    }
}

Related

  1. fileToByteArray(File file)
  2. fileToByteArray(File file)
  3. fileToByteArray(File file)
  4. FiletoByteArray(File file)
  5. fileToByteArray(final File f)