Change only audio data of wav file, keep meta data

Hey there,

I am developping a tool which reads audio samples from a file, does some processing with it and writes the processed sample data back to the file.
My problem is by using an AudioFormatWriter to write to the file, the samples get appended to the file and don’t replace the original samples.

The approach to delete the file first and create a new file with the new samples does not work for me since all the meta data gets lost. I already tried this approach with also reading and writing all meta data but it doesnt work for all meta tags.

Is there some way to only replace the sample data in a wav file and keeping all the other fields as they are?

Couldn’t you scan through the audio file, look for the ‘data chunk’, and replace the data from that position…?

Thanks, thats what I ended up doing.
I was hoping it would have been possible some how with AudioFormatWriter without manually searching for the data chunk position.