In this tutorial you will see how to use the skip method in java.
In this tutorial you will see how to use the skip method in java.In this tutorial, we will discuss the use of available() and skip() function of FileInputStream class. The FileInputStream class creates a input stream for reading bytes from file. The FileInputStream class is available in java.io package.
With the help of this example, you will see how to calculate the size of file and use of skip function. First of all, we will create input stream for reading bytes from file with the FileInputStream class. The availabe() method of the FileInputStream class return available number of bytes in a file, and the skip(long count) method of the FileInputStream class skip given number of byte from input stream.
About FileInputStream API:
The java.io.FileInputStream class extends java.io.IntputStream class. It provides following methods:
Return Type | Method | Description |
int | available() | The available method Returns the integer number of bytes available in this file input stream. |
void | close() | The close() method use to close this file input stream and system resources used by this stream. |
protected void |
finalize() | The finalize() method ensures that all resources for this file are released.. |
FileDescriptor | getFD() | The getFD() method return the object of FileDescriptor that represents the connection to the actual file in the file system. |
int | read() | The read() method reads a single byte from the FileInputStream and returns integer value. |
int | read( byte b, int off, int len ) | The read(...) method reads bytes from the FileInputStream and stores them in buffer of byte array. |
long | skip( int n) | Function skip specified number from input stream. |
import java.io.*; |
C:\>java SkipDemo Size of file : 11 Content of file : bharatsingh Content after skipping two characters from the file :bharsingh |