ObjectInputStream 类的 readUnsignedShort() 方法读取一个无符号的 16 位短字节。
用法
public int readUnsignedShort() throws IOException
参数
没有传递参数。
返回
16 位短读。
抛出
IOException
例子1
import java.io.*;
public class ObjectInputStreamreadunsignedshortExample1 {
public static void main(String[] args) {
short b = 32767;
try {
FileOutputStream outstream = new FileOutputStream("file1.txt");
ObjectOutputStream objoutstream = new ObjectOutputStream(outstream);
objoutstream.writeShort(b);
objoutstream.flush();
ObjectInputStream objinstream = new ObjectInputStream(new FileInputStream("file1.txt"));
// read and print the short value
System.out.println(" short value:" + objinstream.readUnsignedShort());
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
输出:
short value:32767
例子2
import java.io.*;
public class ObjectInputStreamreadunsignedshortExample2
{
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.writeShort(121212);
objoutStream.flush();
// Use of readUnsignedShort() to read Short.
System.out.println("readUnsignedShort():" + objinStream.readUnsignedShort());
}
}
输出:
readUnsignedShort():55676
相关用法
- Java Objectinputstream skipBytes()用法及代码示例
- Java ObjectInputStream readDouble()用法及代码示例
- Java ObjectStreamField getOffset()用法及代码示例
- Java ObjectStreamField compareTo()用法及代码示例
- Java Object hashCode()用法及代码示例
- Java ObjectInputStream readUnsignedByte()用法及代码示例
- Java ObjectInputStream readFields()用法及代码示例
- Java ObjectOutputStream writeFields()用法及代码示例
- Java ObjectInputStream readFully()用法及代码示例
- Java ObjectStreamField getName()用法及代码示例
- Java ObjectInputStream readInt()用法及代码示例
- Java ObjectStreamClass forClass()用法及代码示例
- Java ObjectInputStream read()用法及代码示例
- Java ObjectStreamField getTypeCode()用法及代码示例
- Java ObjectOutputStream writeBytes()用法及代码示例
- Java ObjectInputStream readUTF()用法及代码示例
- Java Object equals(Object obj)用法及代码示例
- Java ObjectInputStream close()用法及代码示例
- Java ObjectOutputStream useProtocolVersion()用法及代码示例
- Java ObjectStreamClass getSerialVersionUID()用法及代码示例
注:本文由纯净天空筛选整理自 Java Objectinputstream readUnsignedShort() Method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。