StringReader class read(char[] cbuf, int off, int len)method example

Reads characters into a portion of an array.


StringReader class read(char[] cbuf, int off, int len)method example. This example shows you how to use read(char[] cbuf, int off, int len)method.This method Reads characters into a portion of an array.

Here is the code:-
/**
 * @Program that Reads characters into a portion of an array.
 * Read1.java 
 * Author:-RoseIndia Team
 * Date:-29-May-2008
 */
import java.io.*;
public class Read1 {
public static void main(String[] args) {
try
{
 String s = "RoseIndia";
//creating the String Reader
StringReader reader = new StringReader(s);  
char arr[]=new char[s.length()+11];
arr[10]='I';
arr[11]='n';
arr[12]='d';
arr[13]='i';
arr[14]='a';
//Reads characters into a portion of an array.
 reader.read(arr,10,s.length());
 System.out.println(arr);
// Closes the stream 
 reader.close();
}  
catch(IOException e)
{
  System.out.print(e.toString());     

     }


}

Output of the program:-
RoseIndia

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US