java 回退流

 1 import java.io.ByteArrayInputStream;
2 import java.io.IOException;
3 import java.io.PushbackInputStream;
4
5
6 public class PushInputStreamDemo {
7 public static void main(String[] args) throws Exception {
8 String str="www.hjw.com";
9 ByteArrayInputStream bai=new ByteArrayInputStream(str.getBytes());
10 PushbackInputStream push=new PushbackInputStream(bai);
11 System.out.println("读取后的数据为:");
12 int temp=0;
13 while((temp=push.read())!=-1){
14 if(temp=='.'){
15 push.unread(temp);
16 temp=push.read();
17 System.out.print("(退回"+(char)temp+")");//为了显示内容,打印出来
18 }else{
19 System.out.print((char)temp);
20 }
21 }
22 }
23 }

 

posted @ 2012-03-26 19:37  谈笑风生膜法师  阅读(746)  评论(0编辑  收藏  举报