BufferedReader reset() method in Java with Examples Last Updated : 05 Jun, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report The reset() method of BufferedReader class in Java is used to fix or mark the position at the last marked position so that the same byte can be read again. Syntax: public void reset() throws IOException Overrides: It overrides the reset() method of Reader class. Parameters: The method does not accept any parameter. Return value: The method does not return any value. Exceptions: The method throws IOException if the mark() method is never called on the stream or if the value of mark is invalid. Below programs illustrate reset() method in BufferedReader class in IO package: Program 1: Assume the existence of the file "c:/demo.txt". Java // Java program to illustrate // BufferedReader reset() method import java.io.*; public class GFG { public static void main(String[] args) { // Read the stream 'demo.txt' // for containing text "GEEKS" FileReader fileReader = new FileReader( "c:/demo.txt"); // Convert fileReader to // bufferedReader BufferedReader buffReader = new BufferedReader( fileReader); // Read and print characters // one by one System.out.println( "Char : " + (char)buffReader.read()); System.out.println( "Char : " + (char)buffReader.read()); System.out.println( "Char : " + (char)buffReader.read()); // Mark is set on the stream buffReader.mark(0); System.out.println( "Char : " + (char)buffReader.read()); // Reset() is invoked buffReader.reset(); // Read and print characters System.out.println( "Char : " + (char)buffReader.read()); System.out.println( "Char : " + (char)buffReader.read()); } } Output: Char : G Char : E Char : E Char : K Char : K Char : S Program 2: Assume the existence of the file "c:/demo.txt". Java // Java program to illustrate // BufferedReader reset() method import java.io.*; public class GFG { public static void main(String[] args) { // Read the stream 'demo.txt' // containing text "GEEKSFORGEEKS" FileReader fileReader = new FileReader( "c:/demo.txt"); // Convert fileReader to // bufferedReader BufferedReader buffReader = new BufferedReader( fileReader); // Read and print characters // one by one System.out.println( "Char : " + (char)buffReader.read()); System.out.println( "Char : " + (char)buffReader.read()); System.out.println( "Char : " + (char)buffReader.read()); System.out.println( "Char : " + (char)buffReader.read()); // Mark is set on the stream buffReader.mark(0); System.out.println( "Char : " + (char)buffReader.read()); // Reset() is invoked buffReader.reset(); // read and print characters System.out.println( "Char : " + (char)buffReader.read()); System.out.println( "Char : " + (char)buffReader.read()); System.out.println( "Char : " + (char)buffReader.read()); System.out.println( "Char : " + (char)buffReader.read()); } } Output: Char : G Char : E Char : E Char : K Char : S Char : S Char : F Char : O Char : R References: https://docs.oracle.com/javase/10/docs/api/java/io/BufferedReader.html#reset() Comment More infoAdvertise with us Next Article Buffer clear() methods in Java with Examples P pp_pankaj Follow Improve Article Tags : Java Java-Functions Java-IO package Practice Tags : Java Similar Reads Buffer reset() methods in Java with Examples The reset() method of java.nio.Buffer Class is used to reset this buffer's position to the previously-marked position. Invoking this method neither changes nor discards the mark's value.Syntax: public Buffer reset() Return Value: This method returns this buffer.Below are the examples to illustrate t 2 min read BufferedInputStream reset() method in Java with Examples The reset() method of BufferedInputStream class in Java is used to reset the position of the stream to the position at the time the mark method was last called. It is used with the combination of mark() method of the same class. General Contract: There are two cases: If mark() and reset() are suppor 3 min read BufferedReader mark() method in Java with Examples The mark() method of BufferedReader class in Java is used to mark the current position in the buffer reader stream. The reset() method of the same BufferedReader class is also called subsequently, after the mark() method is called. The reset() method fixes the position at the last marked position so 3 min read BufferedReader close() method in Java with Examples The close() method of BufferedReader class in Java is used to close the stream and release all the system resources associated with the stream operations. Syntax: public void close() throws IOException Parameters: This method does not accept any parameter. Return value: This method does not return a 2 min read Buffer clear() methods in Java with Examples The clear() method of java.nio.ByteBuffer Class is used to clear this buffer. The position is set to zero, the limit is set to the capacity, and the mark is discarded. Invoke this method before using a sequence of channel-read or put operations to fill this buffer. For example: buf.clear(); // Prepa 3 min read ByteBuffer reset() methods in Java with Examples The reset() method of java.nio.ByteBuffer Class is used to reset this buffer's position to the previously-marked position. Invoking this method neither changes nor discards the mark's value. Syntax: public ByteBuffer reset() Return Value: This method returns this buffer. Below are the examples to il 2 min read Like