回退流 Demo 1
阿新 • • 發佈:2017-06-05
row != push ring pack new nbsp while 字符串
package pushbackInputStream; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.PushbackInputStream; /* * 回退輸入流 :類 PushbackInputStream * * 構造方法: * PushbackInputStream(InputStream in) 創建 PushbackInputStream 並保存其參數(即輸入流 in),以供將來使用。 */ public class PushbackInputStreamDemo {public static void main(String[] args) throws Exception { //定義一個字符串 String str = "hello.world.hah.heihei"; //定義一個內存輸入流 ByteArrayInputStream ba = new ByteArrayInputStream(str.getBytes()); //定義一個回退流對象 PushbackInputStream pd = null; pd = new PushbackInputStream(ba); System.out.println("讀取之後的數據為:"); int temp = 0; while ((temp =pd.read())!=-1){ if (temp == ‘.‘) { pd.unread(temp); temp = pd.read(); System.out.print("(退回"+(char)temp+")"); } else { System.out.print((char)temp); } } }
回退流 Demo 1