Java DataInputStream.readByte()方法示例
DataInputStream.readByte()
方法的语法如下所示。
public final byte readByte() throws IOException
示例
在下面的代码显示如何使用DataInputStream.readByte()
方法。
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
// At: w w W .y II b a I.c O m
public class Main {
public static void main(String[] args) throws IOException {
byte[] buf = { 1, 2, 3, 4, 5 };
InputStream is = new ByteArrayInputStream(buf);
DataInputStream dis = new DataInputStream(is);
while (dis.available() > 0) {
byte b = dis.readByte();
System.out.print(b);
}
}
}
上面的代码生成以下结果。
12345