Sunday, February 25, 2018

Character Stream Class in Java for B.C.A., M.C.A. and all IT Students


--------------------------------------------------------------------------------------------------------------------------
Prepared By : Uday Shah (HOD - IT)
Contact : 7600044051
E-mail : rupareleducation@gmail.com


Programming With Java
Character Stream

In Java, characters are stored using Unicode conventions. Character stream automatically allows us to read/write data character by character. For example FileReader and FileWriter are character streams used to read from source and write to destination. In Java, characters are stored using Unicode conventions. Character stream is useful when we want to process text files. These text files can be processed character by character. A character size is typically 16 bits.



Java FileWriter Class

java FileWriter class is used to write character-oriented data to a file. It is character-oriented class which is used for file handling in java.
Unlike FileOutputStream class, you don't need to convert string into byte array because it provides method to write string directly.
Following is Method of Java File Write
Method
Description
void write(String text)
It is used to write the string into FileWriter.
void write(char c)
It is used to write the char into FileWriter.
void write(char[] c)
It is used to write char array into FileWriter.
void flush()
It is used to flushes the data of FileWriter.
void close()
It is used to close the FileWriter.

 

Java FileReader Class

Java FileReader class is used to read data from the file. It returns data in byte format like FileInputStream class.
It is character-oriented class which is used for file handling in java.
Following is list of Method
Method
Description
int read()
It is used to return a character in ASCII form. It returns -1 at the end of file.
void close()
It is used to close the FileReader class.


Java BufferedWriter Class

Java BufferedWriter class is used to provide buffering for Writer instances. It makes the performance fast. It inherits Writer class. The buffering characters are used for providing the efficient writing of single arrays, characters, and strings.
Method
Description
void newLine()
It is used to add a new line by writing a line separator.
void write(int c)
It is used to write a single character.
void write(char[] cbuf, int off, int len)
It is used to write a portion of an array of characters.
void write(String s, int off, int len)
It is used to write a portion of a string.
void flush()
It is used to flushes the input stream.
void close()
It is used to closes the input stream

Java BufferedReader Class
The Java.io.BufferedReader class reads text from a character-input stream, buffering characters so as to provide for the efficient reading of characters, arrays, and lines.Following are the important points about BufferedReader −
·        The buffer size may be specified, or the default size may be used.
·        Each read request made of a Reader causes a corresponding read request to be made of the underlying character or byte stream.
Method
Description

This method closes the stream and releases any system resources associated with it.
This method marks the present position in the stream.

This method tells whether this stream supports the mark() operation, which it does.
This method reads a single character.
This method reads characters into a portion of an array.
This method reads a line of text.
This method tells whether this stream is ready to be read.


Best of Luck

Please Share and Give your reviews.... Thank you