DataInputStream类readUnsignedByte()方法 (DataInputStream Class readUnsignedByte() method)

  • readUnsignedByte() method is available in java.io package.

    readUnsignedByte()方法在java.io包中可用。

  • readUnsignedByte() method is used to read 1 byte (i.e. 8 bit) of data input and returns an unsigned byte value read.

    readUnsignedByte()方法用于读取1个字节(即8位)的数据输入,并返回读取的无符号字节值。

  • readUnsignedByte() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.

    readUnsignedByte()方法是一个非静态方法,只能通过类对象访问,如果尝试使用类名称访问该方法,则会收到错误消息。

  • readUnsignedByte() method may throw an exception at the time of reading byte.

    readUnsignedByte()方法在读取字节时可能会引发异常。

    • IOException: This exception may throw when this stream is not opened.IOException :如果未打开此流,则可能引发此异常。
    • EndOfFileException: This exception may throw when this stream has reached its endpoint.EndOfFileException :当此流到达其端点时,可能引发此异常。

Syntax:

句法:

    public final int readUnsignedByte();

Parameter(s):

参数:

  • It does not accept any parameter.

    它不接受任何参数。

Return value:

返回值:

The return type of the method is int, it returns 1 byte of data input, manipulated as an unsigned byte value.

方法的返回类型为int ,它返回1个字节的数据输入,并作为无符号字节值进行操作。

Example:

例:

// Java program to demonstrate the example
// of int readUnsignedByte() method of
// DataInputStream
import java.io.*;
public class ReadUnsignedByteOfDIS {public static void main(String[] args) throws IOException {InputStream is_stm = null;
DataInputStream dis_stm = null;
FileOutputStream fos_stm = null;
DataOutputStream dos_stm = null;
byte[] b_arr = {125,
111,
-121,
-112
};
try {// Instantiate FileInputStream,
// DataInputStream, FileOutputStream
// and DataOutputStream
fos_stm = new FileOutputStream("C:\\Users\\Preeti Jain\\Desktop\\programs\\includehelp.txt");
dos_stm = new DataOutputStream(fos_stm);
// Loop to write each byte till end
for (byte val: b_arr) {// By using writeByte() method isto
// write a byte value to the
// DataOutputStream dos_stm
dos_stm.writeByte(val);
}
is_stm = new FileInputStream("C:\\Users\\Preeti Jain\\Desktop\\programs\\includehelp.txt");
dis_stm = new DataInputStream(is_stm);
// Loop To Read Available Data till end
while (dis_stm.available() > 0) {// By using readUnsignedByte() method isto read
// unsigned byte at a time from dis_stm
int in = dis_stm.readUnsignedByte();
System.out.println("dis_stm.readUnsignedByte(): " + in );
}
} catch (Exception ex) {System.out.println(ex.toString());
} finally {// To free system resources linked
// with these streams
if (is_stm != null)
is_stm.close();
if (dis_stm != null)
dis_stm.close();
if (dos_stm != null)
dos_stm.close();
if (fos_stm != null)
fos_stm.close();
}
}
}

Output

输出量

dis_stm.readUnsignedByte(): 125
dis_stm.readUnsignedByte(): 111
dis_stm.readUnsignedByte(): 135
dis_stm.readUnsignedByte(): 144

翻译自: https://www.includehelp.com/java/datainputstream-readunsignedbyte-method-with-example.aspx

Java DataInputStream readUnsignedByte()方法(带示例)相关推荐

  1. java datainputstream_Java DataInputStream readUnsignedByte()方法

    Java DataInputStream readUnsignedByte()方法 java.io.DataInputStream.readUnsignedByte() 用于读取一个输入字节,将其零扩 ...

  2. Java IOUtils.copy方法代码示例(亲测)

    本文整理汇总了Java中org.apache.commons.io.IOUtils.copy方法的典型用法代码示例.如果您正苦于以下问题:Java IOUtils.copy方法的具体用法?Java I ...

  3. java getmonth_Java LocalDateTime类| 带示例的getMonth()方法

    java getmonth LocalDateTime类getMonth()方法 (LocalDateTime Class getMonth() method) getMonth() method i ...

  4. java user directory,Java ProcessBuilder directory()方法与示例

    语法:public File directory (); public ProcessBuilder directory (File dir); ProcessBuilder类directory()方 ...

  5. Java序列化魔术方法及其示例使用

    在上一篇文章中, 您需要了解有关Java序列化的所有知识 ,我们讨论了如何通过实现Java序列化来启用类的可序列化性. Serializable接口. 如果我们的类未实现Serializable接口, ...

  6. catalog java,Java Connection getCatalog()方法与示例

    通常,目录是一个目录,其中包含有关数据集,文件或数据库的信息.而数据库目录中包含所有数据库,基本表,视图(虚拟表),同义词,值范围,索引,用户和用户组的列表. Connection接口的getCata ...

  7. filepermission java,Java FilePermission getActions()方法与示例

    FilePermission类getActions()方法getActions()方法在java.io包中可用. getActions()方法用于检查此FilePermission和给定对象在路径名和 ...

  8. java方法参数Bundle,Java ResourceBundle keySet()方法及示例

    ResourceBundle类keySet()方法keySet()方法在java.util包中可用. keySet()方法用于从此ResourceBundle及其超级捆绑包中获取所有现有键,以在Set ...

  9. java exec waitfor,Java Process waitFor()方法与示例

    流程类waitFor()方法在java.lang包中提供了waitFor()方法. waitFor()方法用于使当前正在运行的线程在需要时等待,直到由该Process对象表示的进程完成其终止为止. 当 ...

最新文章

  1. 华为今年不会发布鸿蒙系统的手机,华为:今年不会推出鸿蒙系统手机 将坚守安卓生态...
  2. 如何从零起步搭建一个分布式对象存储的架构
  3. linux 终端提示符
  4. [SDUT](3329)顺序表应用5:有序顺序表归并 ---有序表归并(线性表)
  5. ubuntu修改登陆用户名称_修改ubuntu的用户名(注意用户名和主机名的区别)
  6. 从变分编码、信息瓶颈到正态分布:论遗忘的重要性
  7. SAP 不同 ABAP 系统里同一 Customizing activity 的显示差异分析
  8. 进阶– Java EE 7前端5强
  9. 网络中的那些事儿(五)之校园网规划综述
  10. 多智能体强化学习MAPPO源代码解读
  11. xp系统扫描仪服务器,xp系统扫描仪添加步骤全程的图文教程
  12. libvlc外用api
  13. 01336软件项目管理复习
  14. python 拓扑排序 dfs bfs_图遍历算法之DFS/BFS
  15. 084 php获取美元人民币汇率方法
  16. 【笔记】脉搏波手环自研之路开启
  17. win10找不到你的相机,错误代码0xA00F4244解决办法
  18. java判断是否安装了pdf_java判断上传文件是否为pdf java图像上传中如何判断是否是jpg格式...
  19. 1月共有49个区块链项目进行ICO,卖牛肉的都来玩区块链了!
  20. linux系统英伟达gpu驱动卸载_在Linux系统中卸载手动安装的Nvidia驱动程序

热门文章

  1. ae正在发生崩溃_AE错误:正在发生崩溃的解决方法,原创问题解决方案
  2. 公关文秘专业要学计算机,文秘相关专业有哪些
  3. easyui中onchange事件_React中类似Vue的“模板语法”
  4. android键盘移动光标,在Android键盘上完成键
  5. authinfo.php,【nginxphp】后台权限认证方式
  6. 弹跳机器人 桌游_MIT机器人轻松搞定桌游叠叠乐:你能玩过它算我输 |《科学》子刊...
  7. dubbo全局异常处理_基于spring aop的dubbo异常统一处理
  8. java技术简介英文_Java技术常见的英文缩写
  9. 编写第一个Spring程序——IOC实现
  10. linux高负载下彻底优化mysql数据库