mark()和reset()方法如何正常工作(在下面的代码中),一步一步?我试图写我自己的例子,但开始抛出错误的标记异常或类似的,我不明白在这个代码中放置标记和重置方法的要点是什么,因为我看不到这个或没有区别.
import java.io.*; class BufferedInputStreamDemo { public static void main(String args[]) { String s = "© is a copyright symbol," + "however © isn't.\n"; byte buf[] = s.getBytes(); ByteArrayInputStream in = new ByteArrayInputStream(buf); int c; boolean marked = false; //try_with_resources try (BufferedInputStream f = new BufferedInputStream(in)) { while ((c = f.read()) != -1) { switch (c) { case '&': if (!marked) { f.mark(32); marked = true; } else { marked = false; } break; case ';': if (marked) { marked = false; System.out.print("(c)"); } else System.out.print((char) c); break; case ' ': if (marked) { marked = false; f.reset(); System.out.print("&"); } else System.out.print((char) c); break; default: if (!marked) System.out.print((char) c); break; } } } catch (IOException e) { System.out.println("I/O Error: " + e); } } }