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.pswp.cn/news/542388.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/542388.shtml
英文地址,請注明出處:http://en.pswp.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;可以通過本地連接向活動服務器發送消息。實際…