PushBackInputStream 回退流操作用法

String fileName = "Hellow,How Are You!";
		PushbackInputStream push = null;
		ByteArrayInputStream bat = null;
		bat = new ByteArrayInputStream(fileName.getBytes());
		push = new PushbackInputStream(bat); //回退流
		int temp = 0;
		while ((temp = push.read()) != -1) {
			if (temp == ',') {  //遇到逗号,在逗号前加(,boy)
				push.unread(temp);
				temp = push.read();
				System.out.print(",boy" + (char)temp );
			} else {
				System.out.print( (char)temp); //正常打印流内容
			}
		}

打印如下:   Hellow,boy,How Are You!

你可能感兴趣的:(PushBackInputStream 回退流操作用法)