Java Methods of FileReader

www.igift‮i‬dea.com

Java FileReader inherits several methods from its superclass, InputStreamReader, as well as some methods of its own. Here are some of the methods available in the FileReader class:

  1. read(): This method reads a single character from the input stream and returns it as an integer. If the end of the stream has been reached, it returns -1.

  2. read(char[] cbuf): This method reads characters from the input stream into the cbuf character array. It returns the number of characters read, or -1 if the end of the stream has been reached.

  3. read(char[] cbuf, int off, int len): This method reads up to len characters from the input stream into the cbuf character array, starting at the specified off offset. It returns the number of characters read, or -1 if the end of the stream has been reached.

  4. skip(long n): This method skips over and discards up to n characters of data from the input stream.

  5. ready(): This method returns true if the input stream is ready to be read, false otherwise.

  6. close(): This method closes the input stream and releases any system resources associated with it.

Note that like all input stream classes, FileReader is designed to read characters from a stream one at a time. If you need to read a large amount of data at once, you may want to consider using a buffer or a higher-level class such as BufferedReader.