Java.io.CharArrayReader.mark() 方法


Java.io.CharArrayReader.mark() 方法

package com.codingdict;



import java.io.CharArrayReader;

import java.io.IOException;



public class CharArrayReaderDemo {



   public static void main(String[] args) {      CharArrayReader car = null;

      char[] ch = {'A', 'B', 'C', 'D', 'E'};



      try {



         // create new character array reader

         car = new CharArrayReader(ch);



         // read and print the characters from the stream

         System.out.println(car.read());

         System.out.println(car.read());



         // mark() is invoked at this position

         car.mark(0);

         System.out.println("Mark() is invoked");

         System.out.println(car.read());

         System.out.println(car.read());



         // reset() is invoked at this position

         car.reset();

         System.out.println("Reset() is invoked");

         System.out.println(car.read());

         System.out.println(car.read());

         System.out.println(car.read());



      } catch(IOException e) {



         // if I/O error occurs

         System.out.print("Stream is already closed");

      } finally {



         // releases any system resources associated with the stream

         if(car!=null)

            car.close();

      }

   }

}