Java Methods of FileReader
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:
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.read(char[] cbuf)
: This method reads characters from the input stream into thecbuf
character array. It returns the number of characters read, or -1 if the end of the stream has been reached.read(char[] cbuf, int off, int len)
: This method reads up tolen
characters from the input stream into thecbuf
character array, starting at the specifiedoff
offset. It returns the number of characters read, or -1 if the end of the stream has been reached.skip(long n)
: This method skips over and discards up ton
characters of data from the input stream.ready()
: This method returnstrue
if the input stream is ready to be read,false
otherwise.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
.