Suppose we have a file named input.txt with the following content. Here is how we can implement Reader using the FileReader class. skip() - discards the specified number of characters from the stream.reset() - returns the control to the point in the stream where the mark is set.mark() - marks the position in the stream up to which data has been read.read(char array, int start, int length) - reads the number of characters equal to length from the stream and stores in the specified array starting from the start.read(char array) - reads the characters from the stream and stores in the specified array.ready() - checks if the reader is ready to be read.Here are some of the commonly used methods: The Reader class provides different methods that are implemented by its subclasses. Note: We can also create readers from other subclasses of Reader. Hence we cannot create an object of Reader. It is because Reader is an abstract class. Here, we have created a reader using the FileReader class. Once we import the package, here is how we can create the reader. In order to create a Reader, we must import the java.io.Reader package first. We will learn about all these subclasses in the next tutorial. In order to use the functionality of Reader, we can use its subclasses. ![]() However, its subclasses can be used to read data. ![]() Since Reader is an abstract class, it is not useful by itself. The Reader class of the java.io package is an abstract superclass that represents a stream of characters.
0 Comments
Leave a Reply. |