Reader Read2() Example
Reads characters into a portion of an array.
Reader class Read2() method example. This example shows you how to use Read2() 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.
* Read2.java
* Author:-RoseIndia Team
* Date:-5-jun-2008
*/
import java.io.*;
public class Read2 {
public static void main(String[] args) throws IOException {
String s = "RoseIndia";
StringReader reader = new StringReader(s);
char[] newArr = new char[s.length() + 11];
newArr[10] = 'R';
newArr[11] = 'o';
newArr[12] = 'H';
newArr[13] = 'l';
newArr[14] = 'N';
newArr[15] = 'I';
reader.read(newArr, 0, s.length());
System.out.print("The new array contains: ");
System.out.println(newArr);
reader.close();
}
} |
Output of the Program
| The new array contains: RoseIndiaROHINI |
|