Java-io-bytearrayinputstream-skip
提供:Dev Guides
Java.io.ByteArrayInputStream.skip()メソッド
説明
- java.io.ByteArrayInputStream.skip(long n)*メソッドは、入力ストリームからnバイトをスキップします。
宣言
以下は* java.io.ByteArrayInputStream.skip(long n)*メソッドの宣言です-
public long skip(long n)
パラメーター
*n* -スキップされるバイト数
戻り値
このメソッドは、スキップされた実際のバイト数を返します。
例外
NA
例
次の例は、java.io.ByteArrayInputStream.skip(long n)メソッドの使用方法を示しています。
package com.finddevguides;
import java.io.ByteArrayInputStream;
import java.io.IOException;
public class ByteArrayInputStreamDemo {
public static void main(String[] args) throws IOException {
byte[] buf = {65, 66, 67, 68, 69};
ByteArrayInputStream bais = null;
try {
//create new byte array input stream
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);
}
} catch(Exception e) {
//if I/O error occurs
e.printStackTrace();
} finally {
if(bais!=null)
bais.close();
}
}
}
上記のプログラムをコンパイルして実行すると、次の結果が生成されます-
65
67
69