There are quite a few reasons that a programmer would like to write to a file in binary but the main reasons are speed, space and precision. Along with those three it is also important to understand when you are going to want to write in binary and when not to.
Speed is a great advantage to writing to files in binary. It allows you to simply pull the information that you want and load it into variables and objects effectively and easily. As you would try to do the same with its counter part you would instead have to go through each line, looping and parsing the information as you go which is not the most effective way to read a file. Using the methods that come with the ObjectOutputStream you can simply write “writeInt(variableInt);” and the data will be written to the file in binary.
The second great advantage to writing is binary is the space. Your files will be much more compact when everything is saved in binary and this makes an especially large difference when you have to pull large amounts of information from a file. Since everything is made up of a set amount of bytes you can compress more into one file by not having any white space.
The third reason to why binary is a good alternative is the precision of writing what is in memory to the file. There is no parsing, the files are written and pulled as they once where when they were placed in memory at one point in time. This allows for less of a risk factor for your programs to stop working on a client and will allow you to have more trust in what you are pulling out of a saved file.
There are times that you will want to write to a file using the full print writer over binary and this is when you have something like a crash log that allows a user to read what happened when the program crashed, where the bug was etc. Aside from information you want to be seen the upside of binary is quite significant. It allows you to have your own set pattern as to writing and pulling information making it harder for someone to go into your file and know what they are changing. And example of this would be a video game. You don’t want someone able to simple log in and change his or her score. You would be better off if they were unable to read the file.
Keeping information secretive is a great part about binary files. Sure you can crack it using patterns but it is less likely a general user will be able to do so unless they know how the program was written.