Java.io.Reader.read Char len() 方法


Java.io.Reader.read Char len() 方法

package com.codingdict;



import java.io.*;



public class ReaderDemo {



   public static void main(String[] args) {

      String s = "Hello world";



      // create a StringReader

      Reader reader = new StringReader(s);



      // create a char array to read chars into

      char cbuf[] = new char[5];



      try {



         // read characters into a portion of an array.

         System.out.println("" + reader.read(cbuf, 0, 5));



         // print cbuf

         System.out.println(cbuf);



         // close the stream 

         reader.close();



      } catch (IOException ex) {

         ex.printStackTrace();

      }

   }

}