PushbackInputStream能够在字节流中插入字符, 构造函数能够定义unread是buffer的字节数。 java
import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.PushbackInputStream; public class PushbackTest { public static void main(String[] args) throws IOException { PushbackInputStream push = new PushbackInputStream( new ByteArrayInputStream("hello, world!".getBytes()), 10); int temp = 0; while ((temp = push.read()) != -1) { if (temp == ',') { push.unread("(...)".getBytes()); } System.out.print((char) temp); } } }