Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert .wav file into byte array?

Tags:

java

file

I have a .wav file in my disk drive. I need to convert that .wav file to byte array using java.

Can anyone help?

like image 232
user74 Avatar asked Jan 15 '23 19:01

user74


2 Answers

You can use Files.readAllBytes to achieve this.

Read all the bytes from a file. The method ensures that the file is closed when all bytes have been read or an I/O error, or other runtime exception, is thrown.

like image 170
dsgriffin Avatar answered Jan 23 '23 05:01

dsgriffin


For JRE < 1.7, regardless of extension

File file = new File(filePath);
InputStream fis = new FileInputStream(file);
byte[] buffer = new byte[(int)file.length()];
fis.read(buffer, 0, buffer.length);
fis.close();
like image 26
Mehmet Ataş Avatar answered Jan 23 '23 04:01

Mehmet Ataş