This java example will demonstrate writing a byte array to a file using java, google guava, apache commons. When each test is run it will write 'fileAsByteArray' which represents 'File to byte array' string to the OUTPUT_FILE_NAME.
Straight up Java
Using a java solution that would work with java 1.4 and above, we will write a byte array to a file using FileOutputStream by passing in the byte array to its constructor. Next calling the writes method will write the length of the bytes from the specified array to the file output stream.
Java 7 File I/O
Using Files, a java utility class introduced in java 7, write byte array into file by calling the write passing in the Path where the file should we written to the array. There is a 3rd parameter not shown below which allows you to specify options on how the file is created. For instance, if you want to truncate and existing file you can pass in
This snippet will show how to write the content of a byte array to a file using guava Files utility class.
Apache commons has a similar method above for writing a byte array to a file.