Here you can find the source of fileToByteArray(File file)
public static byte[] fileToByteArray(File file) throws IOException
//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; } }