Here you can find the source of readFileAtOnce(final File file)
Parameter | Description |
---|---|
file | a java.io.File object. |
Parameter | Description |
---|
public static byte[] readFileAtOnce(final File file) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.FileInputStream; import java.io.IOException; public class Main { /**// ww w .ja va2 s .c om * Reads the contents of the file at once and returns the byte array. * * @param file a {@link java.io.File} object. * @throws java.io.IOException if any. * @return an array of byte. */ public static byte[] readFileAtOnce(final File file) throws IOException { final FileInputStream fIn = new FileInputStream(file); return readFileAtOnce(fIn); } /** * Reads the contents of the file at once and returns the byte array. * * @param filename * name of the file. * @throws java.io.IOException if any. * @return an array of byte. */ public static byte[] readFileAtOnce(final String filename) throws IOException { final FileInputStream fIn = new FileInputStream(filename); return readFileAtOnce(fIn); } /** * Reads the contents of the file input stream. (Why not an InputStream btw?). * * @param fIn * @return * @throws IOException */ private static byte[] readFileAtOnce(final FileInputStream fIn) throws IOException { final byte[] ret = new byte[fIn.available()]; fIn.read(ret); fIn.close(); return ret; } }