Here you can find the source of getBytesFromFile(File file)
Parameter | Description |
---|---|
file | a parameter |
public static byte[] getBytesFromFile(File file)
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.RandomAccessFile; public class Main { /**/*from w w w. j a v a 2 s . co m*/ * Returns a byte stream from the given file. * @param file * @return byte[] File Bytes */ public static byte[] getBytesFromFile(File file) { byte[] bytesArray = null; try { RandomAccessFile raf = new RandomAccessFile(file, "r"); bytesArray = new byte[(int) raf.length()]; raf.read(bytesArray); raf.close(); } catch (Exception e) { System.out.println("Random Access File failed."); } return bytesArray; } }