FileReader Class

Package: java.io

Reads text from a character input stream. Input data is not buffered.

tip.eps Using the BufferedReader class is the preferred way to read data from a character input stream because the BufferedReader class uses buffering to provide more efficient input. For more information, see BufferedReader.

CrossRef.eps The FileReader class is one of many Java I/O classes that use streams. For more information, see Streams (Overview).

Constructor

Constructor

Description

FileReader (File file)

Creates a file reader from the specified File object. It throws FileNotFoundException if the file doesn’t exist or if the file is a directory rather than a file.

Methods

Method

Description

void close()

Closes the file and throws IOException.

int read()

Reads a single character from the file and returns it as an integer. The method returns –1 if the end of the file has been reached. It throws IOException.

int read(char[] buf, int offset, int max)

Reads multiple characters into an array. Offset provides an offset into the array if you don’t want to read the characters into the start of the array. Max specifies the maximum number of characters to read. Returns the number of characters read, or -1 if the end of the input has been reached. This method ...

Get Java For Dummies Quick Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.