java 回退流

来源:互联网 发布:软件测试缺陷管理 编辑:程序博客网 时间:2024/06/05 11:28
 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 }

 

原创粉丝点击