I want to read bytes from a wave file into an array. Since the number of bytes read depends upon the size of the wave file, I\'m creating a byte array with a maximum size of
ArrayList
isn't the solution, ByteArrayOutputStream is the solution. Create a ByteArrayOutputStream
write your bytes to it, and then invoke toByteArray()
to get the bytes.
Example of what your code should look like:
in = new BufferedInputStream(inputStream, 1024*32);
ByteArrayOutputStream out = new ByteArrayOutputStream();
byte[] dataBuffer = new byte[1024 * 16];
int size = 0;
while ((size = in.read(dataBuffer)) != -1) {
out.write(dataBuffer, 0, size);
}
byte[] bytes = out.toByteArray();