skipBytes(int): This method is available in the java.io.DataInputStream class of Java.
Syntax:
int java.io.DataInputStream.skipBytes(int n) throws IOException
This method sees the general contract of the skipBytesmethod of DataInput. Bytes for this operation are read from the contained input stream.
Parameters: One parameter is required for this method.
n: the number of bytes to be skipped.
Returns: the actual number of bytes skipped.
Throws:
1. IOException - if the contained input stream does not support seek, or the stream has been closed and the contained input stream does not support reading after close, or another I/O error occurs.
Approach
Java
import java.io.DataInputStream;import java.io.FileInputStream;import java.io.IOException;import java.io.InputStream;public class DataInputStreamskipBytes {public static void main(String[] args) throws IOException {InputStream in = new FileInputStream("hello.txt");DataInputStream dataInputStream =new DataInputStream(in);int n = 2;System.out.println(dataInputStream.skipBytes(n));dataInputStream.close();}}
Output:
2
No comments:
Post a Comment