StringReader class skip(long ns)method example

Skips the specified number of characters in the stream.


StringReader class skip(long ns)method example. This example shows you how to use skip(long ns) method.This method Skips the specified number of characters in the stream.

Here is the code:-
/**
 * @Program that Skips the specified number of characters in the stream.
 * Skip.java 
 * Author:-RoseIndia Team
 * Date:-29-May-2008
 */
import java.io.*;

public class Skip {
public static void main(String[] args) {
try
{
     String s = "Girish";
//Creating a Stream reader
 StringReader reader = new StringReader(s);
 //char[] c=new char[s.length()];
 for(int i=0;i<s.length();i++)
 {
     if(reader.ready())
     {
         //Read from the underlying string one at a time.
         char c = (char)reader.read();
         System.out.println(c);
         //Skips the specified number of characters in the stream.
         long l=reader.skip(1);
         //Displaying the string after skipping 1 character
         System.out.println("Skipping"+l);
     }
     else
     {
         break;
     }
    
}
 //Closes the stream
 reader.close();
}
catch(IOException e)
{
    
}
    }

}

Output of the program:-
G
Skipping1
r
Skipping1
s
Skipping1
?
Skipping0
?
Skipping0
?
Skipping0

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

HOME | COPYRIGHT | CONTACT US