Java.io.StringReader.read Char() 方法


Java.io.StringReader.read Char() 方法

package com.codingdict;



import java.io.*;



public class StringReaderDemo {



   public static void main(String[] args) {

      String s = "Hello world";



      // create a StringReader

      StringReader 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.

         reader.read(cbuf, 0, 5);



         // print cbuf

         System.out.println(cbuf);



         // Close the stream 

         reader.close();



      } catch (IOException ex) {

         ex.printStackTrace();

      }

   }

}