Java.io.CharArrayReader.read() 方法


Java.io.CharArrayReader.read() 方法

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 = {'H', 'E', 'L', 'L', 'O'};



      try {



         // create new character array reader

         car = new CharArrayReader(ch);



         int value = 0;



         // read till the end of the file

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

            char c = (char)value;



            // print the character

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



            // print the integer

            System.out.println(value);

         }



      } catch(IOException e) {



         // if I/O error occurs

         e.printStackTrace();

      } finally {



         // releases any system resources associated with the stream

         if(car!=null)

            car.close();

      }

   }

}