ByteArrayInputStream skip(long) in Java

skip(long): This method is available in the java.io.ByteArrayInputStream class of Java.

Syntax:

long java.io.ByteArrayInputStream.skip(long n)

This method takes one argument. This method skips n bytes of input from this input stream.

Note: Fewer bytes might be skipped if the end of the input stream is reached.

The actual number k of bytes to be skipped is equal to the smaller of n and count-pos. The value k is added into pos and k is returned.

Parameters: One parameter is required for this method.

n: the number of bytes to be skipped.

Returns: the actual number of bytes skipped.

Exceptions: NA

Approach

Java

import java.io.ByteArrayInputStream;
import java.io.IOException;

public class ByteArrayInputStreamskip {
    public static void main(String[] args) throws IOException {

        byte buf[] = { 1, 2, 3, 4 };
        ByteArrayInputStream byteArrayInputStream =
new ByteArrayInputStream(buf);

        long n = 3;

        System.out.println(byteArrayInputStream.skip(n));
        byteArrayInputStream.close();
    }

}

Output:

3


No comments:

Post a Comment