Java LineNumberInputStream skip() Example

LineNumberInputStream class skip() method example. This example shows you how to use skip() method.


Syntax is : public long skip(long n) throws IOException
Method skips over and discards n bytes of data from this input stream. The skip method may, for a variety of reasons, end up skipping over some smaller number of bytes, possibly 0. The actual number of bytes skipped is returned. If n is negative, no bytes are skipped. This is deprecated method of deprecated class.

Here is the code.
/**
 * @(#) SkipLineNumberInputStream.java
 * A class representing use of method skip() of LineNumberInputStream 
 class in java.io Package. This is deprecated class in java 1.6 API.
 * @Version  05-May-2008
 @author   Rose India Team
 */
import java.io.*;
public class SkipLineNumberInputStream {
     public static void main(String[] argsthrows IOException{

         String str = "MAHENDRA";
     System.out.println("Elements in buffer are : " + str);

       /* Create object of StringBufferInputStream class. This is deprecated 
       class in java api 1.6. */
        StringBufferInputStream obj = new StringBufferInputStream(str);

    // Create object of LineNumberInputStream class.
    LineNumberInputStream objInputStream = new LineNumberInputStream(obj);
       
        // Read from the buffer one character at a time:
        System.out.println("First element is : "+(char)objInputStream.read());
    System.out.println("Next  element is : "+(char)objInputStream.read());
    System.out.println("Next  element is : "+(char)objInputStream.read());

    // skip() method call that skips specified number of elements.
    objInputStream.skip(2);
    System.out.println("skip() method call for 2 elements.");
    System.out.println("Next  element is : "+(char)objInputStream.read());
    System.out.println("Next  element is : "+(char)objInputStream.read());
    System.out.println("Next  element is : "+(char)objInputStream.read());
    }
}

Output of the program.
Elements in buffer are : MAHENDRA
First element is : M
Next  element is : A
Next  element is : H
skip() method call for 2 elements.
Next  element is : D
Next  element is : R
Next  element is : A

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

HOME | COPYRIGHT | CONTACT US