当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Java Objectinputstream readUnsignedShort()用法及代码示例


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 readUnsignedShort() Method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。