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


Java ObjectInputStream readUnsingedByte()用法及代码示例


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