Here you can find the source of readFileBytes(File file)
Parameter | Description |
---|---|
fileName | a parameter |
public static final byte[] readFileBytes(File file) throws IOException
//package com.java2s; //License from project: Apache License import java.io.File; import java.io.FileInputStream; import java.io.IOException; public class Main { /**/*from w ww .j av a 2 s . c o m*/ * Read the file raw content into byte array. * @param fileName * @return */ public static final byte[] readFileBytes(String fileName) throws IOException { File file = new File(fileName); return readFileBytes(file); } /** * Read the file raw content into byte array. * @param fileName * @return */ public static final byte[] readFileBytes(File file) throws IOException { if (file.exists() && file.isFile()) { FileInputStream fis = new FileInputStream(file); int fileLen = (int) file.length(); byte[] buf = new byte[fileLen]; int len = 0; while (len < fileLen) { int n = fis.read(buf, len, fileLen - len); if (n >= 0) { len += n; } else { break; } } return buf; } else { throw new IOException(file + " does not exist or is not file!"); } } }