Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6020481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:34:31+00:00 2026-05-23T03:34:31+00:00

I want to read bytes from a wave file into an array. Since the

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T03:34:31+00:00Added an answer on May 23, 2026 at 3:34 am

    You can have an array of byte like:

    List<Byte> arrays = new ArrayList<Byte>();
    

    To convert it back to arrays

    Byte[] soundBytes = arrays.toArray(new Byte[arrays.size()]);
    

    (Then, you will have to write a converter to transform Byte[] to byte[]).

    EDIT: You are using List<Byte> wrong, I’ll just show you how to read AudioInputStream simply with ByteArrayOutputStream.

    AudioInputStream ais = ....;
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    int read;
    
    while((read = ais.read()) != -1) {
        baos.write(read);
    }
    
    byte[] soundBytes = baos.toByteArray();
    

    PS An IOException is thrown if frameSize is not equal to 1. Hence use a byte buffer to read data, like so:

    AudioInputStream ais = ....;
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    byte[] buffer = new byte[1024];
    int bytesRead = 0;
    
    while((bytesRead = ais.read(buffer)) != -1) {
        baos.write(buffer, 0, bytesRead);
    }
    
    byte[] soundBytes = baos.toByteArray();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to read line n1->n2 from file foo.c into the current buffer. I
I'm doing some Wave file handling and have them read from disk into an
I want to read unsigned bytes from a binary file. So I wrote the
I want to iteratively read a fixed number of bytes in a file, and
I want to read and write from serial using events/interrupts. Currently, I have it
I want to read an xml file, apply a transform, then write to another
I want to read UTF-8 input in Perl, no matter if it comes from
Yes I want to read a simple a logfile into a TStringList and that
Is it possible to read bytes directly from modem or phone line without losing
I want to be able to read a file just as it is being

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.