< Prev
Next >



Character Stream Classes




Character Stream Classes are used to read characters from the source and write characters to destination.

There are two kinds of Character Stream classes - Reader classes and Writer classes.






Reader


Reader class and its subclasses are used to read characters from source.
Reader class is a base class of all the classes that are used to read characters from a file, memory or console. Reader is an abstract class and hence we can't instantiate it but we can use its subclasses for reading characters from the input stream. We will discuss subclasses of Reader class with their code, in the next few articles.





Methods of Reader class.


These methods are of Reader class.
Methods Description
int read() This method reads a characters from the input stream.
int read(char[] ch) This method reads a chunk of characters from the input stream and store them in its char array, ch.
close() This method closes this output stream and also frees any system resources connected with it.





Writer


Writer class and its subclasses are used to write characters to a file, memory or console. Writer is an abstract class and hence we can't create its object but we can use its subclasses for writing characters to the output stream. We will discuss subclasses of Writer with their code in the next few articles.





Methods of Writer class.


Methods of Writer class provide support for writing characters to the output stream. As this is an abstract class. Hence, some undefined abstract methods are defined in ths subclasses of OutputStream.
Methods Description
abstract void flush() This method flushes the output steam by forcing out buffered bytes to be written out.
void write(int c) This method writes a characters(contained in an int) to the output stream.
void write(char[] arr) This method writes a whole char array(arr) to the output stream.
abstract void close() This method closes this output stream and also frees any resources connected with this output stream.



Please share this article -

Facebook Google Pinterest Reddit Tumblr Twitter




< Prev
Next >
< PrintStream
InputStreamReader>
Please subscribe our social media channels for notifications, we post a new article everyday.

Decodejava Google+ Page Decodejava Facebook Page  DecodeJava Twitter Page

Coming Next
-
C++ and Python

Ad2