Simple (but not the best):
Create a byte array, loop, put the result on in.read() into the array? If you need to grow the array, use System.copyArray.
A better option might be too look at
[url=http://java.sun.com/j2se/1.5.0/docs/api/java/io/ByteArrayInputStream.html]ByteArrayInputStream[/url]
and
[url=http://java.sun.com/j2se/1.5.0/docs/api/java/io/InputStream.html#read(byte[])]InputStream.read(byte[][/url].
import java.io.*;
public class ReadFile {
public static byte[] read(File file) throws IOException {
long length = file.length();
if (length > Integer.MAX_VALUE)
throw new IOException("too big");
DataInputStream in = null;
try {
in = new DataInputStream(new FileInputStream(file));
byte[] data = new byte[(int)length];
in.readFully(data);
return data;
} finally {
if (in!=null)
in.close();
}
}
}