Assuming that I have to write to a binary file. I can use the following code
val fos = new FileOutputStream("fileName")
and then use
fos.write(bytes)
Is it always a good idea to chain it with a buffered stream? as in:
val fos = new FileOutputStream("FileName")
val bos = new BufferedOutputStream(fos)
Does the same rule hold for FileInputStream
?
Is it necessary to close fos
in the end (in the chained version)?
EDIT: Found the answer to the last question. It is not necessary to close the inner streams, as mentioned here.