ObjectInputStream 類的 readUnsignedByte() 方法讀取一個無符號的 8 位字節。
用法
public int readUnsignedByte() throws IOException
參數
沒有傳遞參數。
返回
讀取的 8 位字節。
拋出
IOException
例子1
import java.io.*;
public class ObjectInputStreamreadunsignedByteExample1 {
public static void main(String[] args) {
short b = 32767;
try {
FileOutputStream outstream = new FileOutputStream("file1.txt");
ObjectOutputStream objoutstream = new ObjectOutputStream(outstream);
objoutstream.writeByte(b);
objoutstream.flush();
ObjectInputStream objinstream = new ObjectInputStream(new FileInputStream("file1.txt"));
// read and print the using readUnsignedByte
System.out.println(" byte value:" + objinstream.readUnsignedByte());
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
輸出:
byte value:255
例子2
import java.io.*;
public class ObjectInputStreamreadunsignedByteExample2
{
public static void main(String[] args) throws IOException
{
FileOutputStream outstream = new FileOutputStream("file1.txt");
ObjectOutputStream objoutStream = new ObjectOutputStream(outstream);
ObjectInputStream objinStream = new ObjectInputStream(new FileInputStream("file1.txt"));
objoutStream.writeByte(121212);
objoutStream.flush();
System.out.println("readUnsignedShort():" + objinStream.readUnsignedByte());
}
}
輸出:
readUnsignedShort():124
相關用法
- Java ObjectInputStream readUnsignedByte()用法及代碼示例
- Java ObjectInputStream readUnsignedShort()用法及代碼示例
- Java ObjectInputStream readUnshared()用法及代碼示例
- Java ObjectInputStream readUTF()用法及代碼示例
- Java ObjectInputStream readDouble()用法及代碼示例
- Java ObjectInputStream readFields()用法及代碼示例
- Java ObjectInputStream readFully()用法及代碼示例
- Java ObjectInputStream readInt()用法及代碼示例
- Java ObjectInputStream read()用法及代碼示例
- Java ObjectInputStream readField()用法及代碼示例
- Java ObjectInputStream readShort()用法及代碼示例
- Java ObjectInputStream readByte()用法及代碼示例
- Java ObjectInputStream readLong()用法及代碼示例
- Java ObjectInputStream readStreamHeader()用法及代碼示例
- Java ObjectInputStream readObjectOverride()用法及代碼示例
- Java ObjectInputStream readChar()用法及代碼示例
- Java ObjectInputStream readObject()用法及代碼示例
- Java ObjectInputStream readLine()用法及代碼示例
- Java ObjectInputStream readBoolean()用法及代碼示例
- Java ObjectInputStream readFloat()用法及代碼示例
注:本文由純淨天空篩選整理自 Java ObjectInputStream readUnsingedByte() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。