Read the API doc for the write methods you are using for the explanation.
Basically java needs to save the String's length in the file so it knows how long it is. The length is written in binary....