Java FileReader reset() Method
Example
Try to reset a FileReader, and catch the error:
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class Main {
public static void main(String[] args) throws IOException {
FileWriter myWriter = new FileWriter("filename.txt");
myWriter.write("Hello World");
myWriter.close();
try (FileReader myReader = new FileReader("filename.txt")) {
myReader.reset();
} catch (IOException e) {
System.out.println("FileReader does not support reset().");
}
}
}
Definition and Usage
The reset() method is meant to go back to the position that was marked with mark().
But FileReader does not support marks. Its reset() method always throws an IOException. To use mark() and reset(), put the FileReader inside a BufferedReader.
Tip: See the BufferedReader reset() method for an example that works.
Syntax
public void reset()
Parameter Values
None.
Technical Details
| Throws: | IOException - always, because FileReader does not support marks. |
|---|
Related Pages
❮ FileReader Methods