Java FileInputStream.skip(long n)方法範例

2019-10-16 22:14:56

Java FileInputStream.skip(long n)方法範例

FileInputStreamFileInputStream.skip(long n)方法具有以下語法。

public long skip(long n)  throws IOException

範例

在下面的程式碼顯示如何使用FileInputStream.skip(long n)方法。


import java.io.IOException;
import java.io.FileInputStream;

public class Main {
  public static void main(String[] args) throws IOException {
    FileInputStream fis = new FileInputStream("C://test.txt");

    // skip bytes from file input stream
    fis.skip(4); // From: w  ww .y IIB  A I.C  O   m 

    // read bytes from this stream
    int i = fis.read();

    // converts integer to character
    char c = (char) i;
    System.out.print("Character read: " + c);
  }
}