Reader.reset() has the following syntax.
public void reset() throws IOException
In the following code shows how to use Reader.reset() method.
// w ww. j a v a 2s. co m import java.io.*; public class Main { public static void main(String[] args) { String s = "tutorial from java2s.com"; Reader reader = new StringReader(s); try { for (int i = 0; i < 5; i++) { char c = (char) reader.read(); System.out.print(c); } reader.mark(10); for (int i = 0; i < 6; i++) { char c = (char) reader.read(); System.out.println(c); } reader.reset(); for (int i = 0; i < 6; i++) { char c = (char) reader.read(); System.out.println(c); } reader.close(); } catch (IOException ex) { ex.printStackTrace(); } } }
The code above generates the following result.