java 回退流

来源:互联网 发布:光辉战机 知乎 编辑:程序博客网 时间:2024/06/05 09:49
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.PushbackInputStream;


public class PushInputStreamDemo {
public static void main(String[] args) throws Exception {
String str = "www.hjw.com";
ByteArrayInputStream bai = new ByteArrayInputStream(str.getBytes());
PushbackInputStream push = new PushbackInputStream(bai);
System.out.println("读取后的数据为:");
int temp = 0;
while ((temp = push.read()) != -1) {
if (temp == '.') {
push.unread(temp);
temp = push.read();
System.out.print("(退回sssssssss" + (char) temp + ")");// 为了显示内容,打印出来
} else {
System.out.print((char) temp);
}
}
}
}
0 0
原创粉丝点击