首页 > 代码库 > 回退流 Demo2
回退流 Demo2
package pushbackInputStream; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PushbackInputStream; /* * 自己再写一次 */ public class PushbackInputStreamDemo2 { public static void main(String[] args) throws Exception { //定义一个字符串 String str = "hello.hai.heihei.laiba..."; //定义一个内存输入流对象 ByteArrayInputStream bai = new ByteArrayInputStream(str.getBytes()); //定义一个回退流对象 PushbackInputStream pbi = new PushbackInputStream(bai); System.out.println("读取的数据为:"); int temp = 0; while ((temp = pbi.read())!=-1) { if (temp ==‘.‘) { pbi.unread(temp); temp = pbi.read(); System.out.print("(回退"+(char)temp+")"); } else { System.out.print((char)temp); } } } }
回退流 Demo2
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。