• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 232
  • Last Modified:

copying bytes from file

hi there
i have a wav file, i wish to copy the file into a buffer of type Byte and then read from the buffer using java, can any one please help us with the solution, thanks
0
abbas486
Asked:
abbas486
  • 2
1 Solution
 
InteractiveMindCommented:
As in a byte array, or a ByteBuffer instance?

0
 
InteractiveMindCommented:
One solution is to read the file into a byte [] array, via a FileInputStream.
If you then wanted a ByteBuffer, you just use the wrap() method of the ByteBuffer class to shove it into a ByteBuffer.

Perhaps a more efficient approach would be to use a FileChannel to read the file into a MappedByteBuffer instance, as in:

File file = new File( "somebytes.wav" );
fis = new FileInputStream( file );

FileChannel fc = fis.getChannel();
MappedByteBuffer bb = fc.map( FileChannel.MapMode.READ_ONLY, 0, file.length() ) ;
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now