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 1000000. But this is resulting in empty values at the end of the array. So, I wanted to create a dynamically increasing array and I found that ArrayList is the solution. But the read() function of the AudioInputStream class reads bytes only into a byte array! How do I pass the values into an ArrayList instead?
Share
You can have an array of byte like:
To convert it back to arrays
(Then, you will have to write a converter to transform
Byte[]tobyte[]).EDIT: You are using
List<Byte>wrong, I’ll just show you how to readAudioInputStreamsimply withByteArrayOutputStream.PS An
IOExceptionis thrown ifframeSizeis not equal to1. Hence use a byte buffer to read data, like so: