Byte array of unknown length in java February 17, 2023 by Tarik Try ByteArrayOutputStream. You can use write( byte[] ) and it will grow as needed.