FilterReader.reset()方法示例
FilterReader.reset()
具有以下语法。
public void reset() throws IOException
示例
在下面的代码中展示了如何使用FilterReader.reset()
方法。
import java.io.FilterReader;
import java.io.Reader;
import java.io.StringReader;
public class Main {// @ w w w . y i iBa i . c O M
public static void main(String[] args) throws Exception {
Reader r = new StringReader("ABCDEF");
// create new filter reader
FilterReader fr = new FilterReader(r) {
};
// read and print characters one by one
System.out.println("Char : " + (char) fr.read());
System.out.println("Char : " + (char) fr.read());
System.out.println("Char : " + (char) fr.read());
// mark is set on the filter reader
fr.mark(0);
System.out.println("Char : " + (char) fr.read());
System.out.println("reset() invoked");
// reset is called
fr.reset();
// read and print characters
System.out.println("char : " + (char) fr.read());
System.out.println("char : " + (char) fr.read());
}
}
上面的代码生成以下结果。
Ready to read? true