Tutorial below is regarding Java writer class. Java writer class is an abstractly implemented idea for writing text files using character streams. It is defined inside java.io package. This class is the root of all the classes that write character output streams. In short, writer class provides foundation for the classes that write character output streams. This java writer hierarchy contains many classes such as PrintWriter, BufferedWriter, FileWriter, OutputStreamWriter and many more.
Diagram below demonstrates a subset of the Writer hierarchy. Diagram demonstrates the classes that are used to create an OutputStream environment of characters for writing text files.
Class PrintWriter defined inside the abstract class writer, writes or has
function defined to put the data (characters) into the character output
stream. Similarly class BufferedWriter creates a temporary memory called buffer
for the character output stream so that the stream values that are the actually
the characters, can be processed more efficiently. Class FileWriter interconnects
the character output stream to the path of a file. Class OutputStream
Writer creates interface (like a bridge as connector) from a character output stream to a binary
Note: Al l data is stored as text characters with one character per byte on disk.
A Stream is the flow of data from one location to another and an output stream is the flow of data as characters from the internal memory of an application to a disk file. With writer classes data as text are written on text files.
Stream to get its functionality requires layering in which two or more streams
are layered and forms a filtered stream. This filtered stream now possess all
the functionality to perform either Input or Output operation.
While working with writer classes following three different types of exceptions are often generated.
IOException :- Is thrown when an error occurs during I/O processing.
EOFException :- Is thrown when the program control attempts to read beyond the end of the file.
FileNotFoundException :- Is thrown when the program control
attempts to open a file that does not exists .
All the above exceptions can be handled with try and catch blocks. Also can be avoided by using throws keyword.
Syntax for using throws keyword :- throws Exception_name
For example :- throws IOException
We have 1000s of tutorials on our website. Search Tutorials tutorials on our website.
Posted on: December 12, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles