回退流
- 12.14 回退流
- 【例12.67】操作回退流
12.14 回退流
表 12-23 PushbacklnputStream 类的常用方法
表12-24回退流与输入流的对应
【例12.67】操作回退流
package jiaqi;
import java.io.ByteArrayInputStream;
import java.io.PushbackInputStream;
public class demo436_1 {
// private static final PushbackInputStream ByteArrayInputStream = null;
public static void main(String[] args)throws Exception
{
String str = "www.mycomputer.top";
//回退流
PushbackInputStream push = null;
//内存字节输入流
ByteArrayInputStream bai = null;
//实例化
bai = new ByteArrayInputStream(str.getBytes());
//实例化
push = new PushbackInputStream(bai);
int temp = 0;
while((temp = push.read())!=-1)
{
if((char)temp == '.')
{
push.unread(temp);//回退
temp = push.read();//读出
System.out.print("(删除.)");
}
else
{
System.out.print((char)temp);
}
}
}
}