/** * Read and return the entire contents of the supplied {@link File file}. * * @param file the file containing the contents; may be null * @return the contents, or an empty byte array if the supplied file is null * @throws IOException if there is an error reading the content */ public static byte[] readBytes(File file) throws IOException { if (file == null) return new byte[] {}; try (InputStream stream = new BufferedInputStream(new FileInputStream(file))) { return readBytes(stream); } }
/** * Read and return the entire contents of the supplied {@link File file}. * * @param file the file containing the contents; may be null * @return the contents, or an empty byte array if the supplied file is null * @throws IOException if there is an error reading the content */ public static byte[] readBytes(File file) throws IOException { if (file == null) return new byte[] {}; try (InputStream stream = new BufferedInputStream(new FileInputStream(file))) { return readBytes(stream); } }