I need to read a file into a byte array in Java. Fortunately, this question has been answered very well, and I am able to use the nio libraries from Java 7.
Here's the twist though: The resulting byte array needs to have a size which is a multiple of 8. The extra bytes should be null, i.e. \0.
Is there a quick and readable way to pad the byte array with zeros so that its size is a multiple of 8? Note that readability and speed of development is key here - if the best solution adds more than a few lines in addition simply reading the file into a byte array, I'd rather simply copy the entire buffer into a new array.
Edit:
A bit more reading suggests that I can modify this answer and simply round the size of the buffer to the next 8. Any thoughts on the safety and/or effectiveness of this strategy? I believe the bytes in the buffer beyond the end of the file will be initialized to zero and unaffected by the read - is that correct?