Here you can find the source of fileToByteArray(File file)
Parameter | Description |
---|---|
file | the file to convert |
Parameter | Description |
---|
public static byte[] fileToByteArray(File file) throws FileNotFoundException, IOException
//package com.java2s; import java.io.*; public class Main { /**/*from ww w . java 2 s . co m*/ * Loads data from file and converts it to a byte array. * * @param file the file to convert * @return a byte arry containing the converted data * @throws java.io.FileNotFoundException * @throws java.io.IOException */ public static byte[] fileToByteArray(File file) throws FileNotFoundException, IOException { byte[] result; try (FileInputStream fileInputStream = new FileInputStream(file)) { result = new byte[(int) file.length()]; fileInputStream.read(result); } return result; } }