Here you can find the source of readFileBytes(File file)
Parameter | Description |
---|---|
file | a File |
Parameter | Description |
---|---|
IOException | if an error occurs |
public static byte[] readFileBytes(File file) throws IOException
//package com.java2s; /* J_LZ_COPYRIGHT_BEGIN ******************************************************* * Copyright 2001-2011 Laszlo Systems, Inc. All Rights Reserved. * * Use is subject to license terms. * * J_LZ_COPYRIGHT_END *********************************************************/ import java.io.Closeable; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; public class Main { /** Returns the contents of <var>file</var> as a byte[]. * @param file a File//from ww w. j ava 2s . c om * @return a byte[] * @throws IOException if an error occurs */ public static byte[] readFileBytes(File file) throws IOException { InputStream istr = new FileInputStream(file); byte bytes[] = new byte[istr.available()]; istr.read(bytes); istr.close(); return bytes; } /** * Make sure you really want to ignore the exception * before using this. * @param in stream to close w/out throwing an exception */ static public void close(Closeable c) { if (c != null) { try { c.close(); } catch (Exception e) { } } } }