[Java iO] _ rollback stream notes
Objectives of this chapter:
Master the working principle of the rollback stream
Use the pushbackinputstream class to perform the rollback operation.
Common Methods of pushbackinputstream class
Instance code:
Import Java. io. bytearrayinputstream; import Java. io. pushbackinputstream; public class pushinputstreamdemo {public static void main (string ARGs []) throws exception {// All exceptions throw string STR = "www.mldnjava.cn"; // defines the string pushbackinputstream push = NULL; // define the Back-to-Stream object bytearrayinputstream Bai = NULL; // define the memory input stream Bai = new bytearrayinputstream (Str. getbytes (); // instantiate the memory input stream push = new pushbackinputstream (Ba I); // read data from memory system. out. print ("the data after reading is:"); int temp = 0; while (temp = Push. read ())! =-1) {// read the content if (temp = '. ') {// judge whether the read is ". "Push. unread (temp); // put it back into the buffer. Temp = Push. read (); // read the system again. out. print ("(returned" + (char) temp + ")");} else {system. out. print (char) temp); // output content }}}};