InputStream Skip() Example

Skips over and discards n bytes of data from this input stream.


InputStreamclass Skip() method example. This example shows you how to use Skip() method.This method Skips over and discards n bytes of data from this input stream.

Here is the code:-

/**
 * @Program that Skips over and discards n bytes of data from this input stream.
 * Skip.java 
 * Author:-RoseIndia Team
 * Date:-06-Jun-2008
 */
import java.io.*;

public class Skip extends InputStream {

    public int read() throws IOException {
        return 0;
    }

    public static void main(String args[]) throws Exception {

        PipedInputStream pis = new PipedInputStream();
        PipedOutputStream o = new PipedOutputStream();
        pis.connect(o);
        byte b[] {12345};
        o.write(b);
        System.out.println("Byte of data from input stream.");
        //Returns the number of remaining bytes
        while (pis.available() != 0) {
            //Read InputStream
            System.out.println(pis.read());
            // Skips over and discards n bytes of data from this input stream
            pis.skip(1);
        }

        //Closing InputStream
        pis.close();
    }
}

Output of the Program
 Byte of data from input stream.
1
3
5

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

HOME | COPYRIGHT | CONTACT US