Here you can find the source of getByteArray(File file)
public static byte[] getByteArray(File file) throws IOException
//package com.java2s; import java.awt.image.BufferedImage; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; import javax.imageio.ImageIO; public class Main { public static byte[] getByteArray(File file) throws IOException { BufferedImage originalImage = ImageIO.read(file); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(originalImage, "jpg", baos); baos.flush();/* w w w . j av a2 s . c om*/ return baos.toByteArray(); } }