Java.io.CharArrayReader.read len() 方法


Java.io.CharArrayReader.read len() 方法

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'};

      char[] d = new char[5];



      try {



         // create new character array reader

         car = new CharArrayReader(ch);



         // read character to the destination buffer

         car.read(d, 3, 2);



         // for every character in the buffer

         for (char c : d) {

            int i = (int)c;



            if(i == 0) {

               System.out.println("0");

            } else {

               System.out.println(c);

            }



         }

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

      }

   }

}