Java DataInputStream readUnsignedByte()方法(带示例)

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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/542388.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

wpf中groupbox有什么用_展示设计中的标摊是什么 用的什么材料

经常听从事展示设计的工作人员说起标摊,那什么是标摊呢?顾名思义,标摊就是通用标准的国际展会摊位的缩写。但是不少人看到干巴巴的词语还是不能理解。那么这篇文章从用途、材料等方面来详细介绍标摊究竟是什么。 标摊的主要材质是什么一般来说…

Java BigInteger类| nextProbablePrime()方法与示例

BigInteger类nextProbablePrime()方法 (BigInteger Class nextProbablePrime() method) nextProbablePrime() method is available in java.math package. nextProbablePrime()方法在java.math包中可用。 nextProbablePrime() method is used to get the next probable prime n…

SQL 行转列的两种做法

if object_id(tb)is not null drop table tbGocreate table tb(姓名 varchar(10),课程 varchar(10),分数 int)insert into tb values(张三,语文,74)insert into tb values(张三,数学,83)insert into tb values(张三,物理,93)insert into tb values(李四,语文,74)insert into tb…

android一个工程的xml怎么引用另外一个工程的xml,如何在Android中使用XML引用库中另一个包的字符串?...

Androiddocumentation告诉我,我可以使用“包名”访问另一个包中的字符串,无论这意味着什么:[:]/所以在我的清单中,我想访问一个字符串,我已将其放在一个单独的库项目中,在com.globalmentor.android包中 – 毕竟我的R类就是这样:android:label"com.g…

kotlin 类和对象_Kotlin程序| 类和对象的示例(带有学生数据)

kotlin 类和对象In the below program, we are creating a student class to input and print the student data like name, age. It is a simple example of creating class in Kotlin. 在下面的程序中,我们将创建一个学生班级,以输入和打印学生数据&am…

python 复数数组_python的数组运算及推导式的运用

运行方式:缩进 TAb(四格)或者space(1格)注释:#可以在程序后注释文字 或者 ... ,""" ... """ 可以多行注释 中间全为注释数值输出 print(...)图形输出 import matplotlib as pltplt.show()列表 list[] #字符串…

ActiveX: 如何用.inf和.ocx文件生成cab文件

ActiveX: 如何用.inf和.ocx文件生成cab文件 转载于:https://www.cnblogs.com/time-is-life/p/5977962.html

Android工具里没有Android,android – AppCompat工具栏没有显示

在主题中声明.NoActionBar之后,以及将工具栏放在布局中,我的工具栏不会显示.我最终得到的正是你在宣布没有动作栏时所期望的 – 没有动作栏.这是布局:activity_home.xml:layout"layout/app_bar_home"android:layout_width"match_parent&q…

操作系统中的处理机调度调度_操作系统中的多处理器调度

操作系统中的处理机调度调度多处理器操作系统 (Multiprocessor Operating system) A multiprocessor system consists of several processors which share memory. In the multiprocessor, there is more than one processor in the system. The reason we use multiprocessor …

转:Delphi2010新发现-类的构造和析构函数功能

Delphi2010发布了. 虽然凭着对Delphi的热爱第一时间就安装了,但是现在可能是年纪大了,对新事物缺乏兴趣了.一直都没有仔细研究. 今天有点时间试了一下新功能. 本来C#和Delphi.NET是支持类的构造函数/析构函数的(注意不是实例的构造和析构).也就是在模块初始化/卸载的时候会调用…

sed 替换_sed命令批量替换文件内容

“ 开发人员有时会大批量替换文件内容,sed命令是一个很好用的工具。”01—暴力替换方式近期有个临时任务,将系统中所有"帐"替换为"账",那"帐"和"账"有啥区别呢;1、账的部首是贝;帐的部首是巾。2、账是关于货币、…

android 模仿uc标签页,模仿UCweb菜单 - 白羽雕弓 - 博客园

UCWeb的菜单看起来不错,自己想模仿做一个,苦恼一直没有思路google了几天,终于找到一个帖子 http://www.eoeandroid.com/viewthread.php?tid28824按照上面提供的思路实现了1、保留menu按键作用2、用popupwindow作为菜单显示容器3、用GridVie…

ipv6路由协议配置_IPV6寻址,标头和路由协议

ipv6路由协议配置The IPV6 address is 128 bits. Whereas IPV4 is represented by 4 groups of decimal numbers, same IPV6 is represented by 8 groups of hexadecimal numbers. The example of IPV6 address is 2001:0db8:85a3:0000:0000:8a2e:0370:7334. IPV6地址是128位。…

rpc框架

Motan,dubbo转载于:https://www.cnblogs.com/zhangshiwen/p/5980886.html

android webview 监听js,Android webview与js的数据交互

项目要用到Webview和js交互,查了查以前的项目感觉还是有必要整理下的。简单描述下项目中用到的地方,比如说在web页需要用到登录的地方点击登录跳转到APP原生登录界面去登录,点击web页的拨打电话弹出原生dialog询问是否拨打,点击we…

c ++查找字符串_C ++异常处理| 查找输出程序| 套装1

c 查找字符串Program 1: 程序1&#xff1a; #include <iostream>using namespace std;int main(){try {int num1 10;int num2 0;int res 0;res num1 / num2;}catch (exception e) {cout << "Exception: Divide By Zero" << endl;}return 0;}O…

python的repr和str有什么不同_str()和repr()的异同

str()函数和repr()函数&#xff0c;都是Python内置的标准函数。这两个函数都是根据参数对象返回一个字符串&#xff0c;但是又有一些不一样的地方。我们在使用的时候&#xff0c;常常搞混&#xff0c;倾向于使用简单明了的str()函数&#xff0c;而搞不清楚为什么还有一个不知所…

android web通讯录,Android手机开发之通讯录

Android手机开发——通讯录实现增加、查询、修改、删除的功能&#xff0c;输入联系人信息&#xff0c;点击“添加”按钮&#xff0c;可以添加联系人信息到数据库&#xff1b;点击“查询”按钮&#xff0c;会发现添加的联系人信息显示在界面中&#xff1b;重新输入联系人电话&am…

有关UITableView--cell复用问题

近来用Tableview做了一个九宫格。过程中碰到了两个cell复用问题。 问题一&#xff1a; 在cell中为button添加addTarget点击事件时&#xff0c;出现后面的cell会重叠它前面cell的事件。代码如下&#xff1a; C代码 static NSString *CellWithIdentifier "DiscoverHomeTab…

python客户端和服务端实验_结合服务器和客户端python

我正在尝试使用python(稍后可能用c语言)和TCP套接字制作一个本地网络聊天程序。我的目的是让服务器监听当前计算机的地址以获取传入消息&#xff0c;并将这些消息转发给客户端(我现在还不确定)。客户端将是一个简单的gui&#xff0c;可以通过本地连接向活动服务器发送消息。实际…