File Handling in Java27 Jun 2012
In Java, File I/O is handled by
FileOutputStream class provided by
Byte Streams - Java Byte Streams are used to perform input and output of 8-bit bytes.
Character Streams - Java Character Streams are used to perform 16-Bit Unicode Stream Operations.
FileReader are used in character streams.
FileWriter is a subclass of
FileOutputStream is helpful in wrapping file stream within character based object (Compared to Byte Oriented ).
FileWriter writes two bytes at a time. For character based it’s suggested to use FileWriter to create stream, which creates an internal FileOutputStream to write bytes to the specified file.
Second step deals with
BufferedWriter class which writes text to character output stream. And using the write() method, we can write to the file specified in the FileWriter.