Java.io.CharArrayReader.skip() 方法


Java.io.CharArrayReader.skip() 方法

package com.codingdict;



import java.io.CharArrayReader;

import java.io.IOException;



public class CharArrayReadDemo {



   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);



         int value = 0;



         // read till the end of the stream

         while((value = car.read())!=-1) {



            // convert integer to char

            char c = (char)value;



            // print characters

            System.out.print(c + "; ");



            // skip single character

            long l = car.skip(1);

            System.out.println("Characters Skipped : "+l);

         }



      } catch(IOException e) {



         // if I/O error occurs

         e.printStackTrace();

      } finally {



         // releases any system resources associated with the stream

         if(car!=null)

            car.close();

      }

   }

}