ByteArrayInputStream.skip(long n)方法範例

2019-10-16 22:17:15

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

ByteArrayInputStreamJava ByteArrayInputStream.skip(long n)方法的語法如下。

public long skip(long n)

範例

在下面的程式碼中展示了如何使用ByteArrayInputStream.skip(long n)方法。

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

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

        byte[] buf = { 65, 66, 67, 68, 69 };

        // create new byte array input stream
        ByteArrayInputStream bais = new ByteArrayInputStream(buf);

        int value = 0;

        // read till the end of the stream
        while ((value = bais.read()) != -1) {

            // skip single byte
            bais.skip(1);
            System.out.println(value);
        }

    }
}

執行上面的程式碼,得到如下結果 -

65
67
69