Here you can find the source of getBytes(String fileName)
public static byte[] getBytes(String fileName)
//package com.java2s; //License from project: Apache License import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; public class Main { public static byte[] getBytes(String fileName) { return getBytes(new File(fileName)); }/*from w w w . j a v a2 s . c o m*/ public static byte[] getBytes(File file) { byte[] outputStr = null; BufferedInputStream buffStr = null; String fileName = ""; try { fileName = file.getName(); FileInputStream fileStr = new FileInputStream(file); System.out.println("File Stream: " + fileStr.available()); buffStr = new BufferedInputStream(fileStr); System.out.println("Buffered Stream: " + buffStr.available()); outputStr = new byte[buffStr.available()]; buffStr.read(outputStr, 0, outputStr.length); buffStr.close(); } catch (Exception ex) { System.out.print("Unable to extract bytes from File: " + fileName); System.out.println(" : " + ex.getMessage()); // ex.printStackTrace(); throw new RuntimeException("Unable to extract bytes from File: " + fileName); } return outputStr; } }