Java ObjectInputStream readByte()方法與示例

ObjectInputStream類readByte()方法 (ObjectInputStream Class readByte() method)

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

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

  • readByte() method is used to read a byte (i.e. 8 bit) of data from this ObjectInputStream.

    readByte()方法用于從此ObjectInputStream讀取一個字節(即8位)的數據。

  • readByte() 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.

    readByte()方法是一種非靜態方法,只能通過類對象訪問,如果嘗試使用類名稱訪問該方法,則會收到錯誤消息。

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

    readByte()方法在讀取字節時可能會引發異常。

    • IOException: This exception may throw when getting any input/output error while performing.IOException :在執行過程中遇到任何輸入/輸出錯誤時,可能引發此異常。
    • EOFException: This exception may throw when the end of the file is reached.EOFException :到達文件末尾時,可能會引發此異常。

Syntax:

句法:

    public byte readByte();

Parameter(s):

參數:

  • It does not accept any parameter.

    它不接受任何參數。

Return value:

返回值:

The return type of the method is byte, it returns the byte value read.

該方法的返回類型為byte ,它返回讀取的字節值。

Example:

例:

// Java program to demonstrate the example 
// of byte readByte() method of 
// ObjectInputStream
import java.io.*;
public class ReadByteOfOIS {
public static void main(String[] args) throws Exception {
// Instantiates ObjectOutputStream , ObjectInputStream 
// FileInputStream and FileOutputStream
FileOutputStream file_out_stm = new FileOutputStream("D:\\includehelp.txt");
ObjectOutputStream obj_out_stm = new ObjectOutputStream(file_out_stm);
FileInputStream file_in_stm = new FileInputStream("D:\\includehelp.txt");
ObjectInputStream obj_in_stm = new ObjectInputStream(file_in_stm);
// By using writeUTF() method is to write
// string to the obj_out_stm stream
obj_out_stm.writeUTF("Java World!!!");
obj_out_stm.flush();
while (obj_in_stm.available() > 0) {
// By using readByte() method is to read
// string characters as a byte
byte val = (byte) obj_in_stm.readByte();
System.out.println("obj_in_stm.readByte(): " + val);
}
// By using close() method is to 
// close all the streams 
file_in_stm.close();
file_out_stm.close();
obj_in_stm.close();
obj_out_stm.close();
}
}

Output

輸出量

obj_in_stm.readByte(): 0
obj_in_stm.readByte(): 13
obj_in_stm.readByte(): 74
obj_in_stm.readByte(): 97
obj_in_stm.readByte(): 118
obj_in_stm.readByte(): 97
obj_in_stm.readByte(): 32
obj_in_stm.readByte(): 87
obj_in_stm.readByte(): 111
obj_in_stm.readByte(): 114
obj_in_stm.readByte(): 108
obj_in_stm.readByte(): 100
obj_in_stm.readByte(): 33
obj_in_stm.readByte(): 33
obj_in_stm.readByte(): 33

翻譯自: https://www.includehelp.com/java/objectinputstream-readbyte-method-with-example.aspx

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/542036.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/542036.shtml
英文地址,請注明出處:http://en.pswp.cn/news/542036.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

openresty—實現緩存前移

含義及理解: OpenResty(又稱:ngx_openresty) 是一個基于 NGINX 的可伸縮的 Web 平臺,由中國人章亦春發起,提供了很多高質量的第三方模塊。 其目標是讓Web服務直接跑在Nginx服務內部,充分利用Nginx的非阻塞I/O模型&am…

Nginx+Keepalived+Tomcat之動靜分離的web集群

NginxKeepalivedTomcat之動靜分離的web集群 博客分類: webserverNginxKeepalivedTomcat之動靜分離的web集群為小公司提供大概一天持續在100萬/日之間訪問的高性能、高可用、高并發訪問及動靜分離的web集群方案NginxKeepalived 高可用、反向代理NginxPHP …

安裝完成后的配置_cent os7 默認安裝后的一般配置

在安裝cent os7后,進入系統會出現一些命令無法執行。這是因為最小化沒有安裝包含的軟件包。這時候先要配置一下基本的IP參數,(包括動態,靜態,或者是雙網卡綁定)。我們在虛擬機中模擬操作一下,配置文件在/etc/sysconfig…

Java Integer類lowerOneBit()方法與示例

整數類lowerOneBit()方法 (Integer class lowestOneBit() method) lowestOneBit() method is available in java.lang package. minimumOneBit()方法在java.lang包中可用。 lowestOneBit() method is used to find at most only single 1’s bit from the rightmost side one b…

lnmp構架——對tomcat詳解

tomcat的安裝部署 安裝jdk和tomcat tar zxf jdk-7u79-linux-x64.tar.gz -C /usr/local/ tar zxf apache-tomcat-7.0.37.tar.gz -C /usr/local/做好軟連接便于訪問 cd /usr/local ln -s jdk1.7.0_79/ java ln -s apache-tomcat-7.0.37/ tomcat配置環境變量 vim /etc/profile…

Linux 查找文件

find 查找目錄 -name "文件名"find / -name "php.ini"locate 文件名locate php.ini 一:locate命令 locate命令用于查找文件,它比find命令的搜索速度快,它需要一個數據庫,這個數據庫由每天的例行工作&#xff…

Java GregorianCalendar hashCode()方法與示例

GregorianCalendar類的hashCode()方法 (GregorianCalendar Class hashCode() method) hashCode() method is available in java.util package. hashCode()方法在java.util包中可用。 hashCode() method is used to returns the hash code for this GregorianCalendar. hashCode…

python元組為什么不可變_為什么python字符串和元組是不可變的?

我不知道為什么字符串和元組是不可變的;使它們不可變的優點和缺點是什么?除了Python解釋器的內部實現,這種設計在編寫程序上是否有很好的意義?(例如,如果元組和字符串是可變的,會更容易嗎?)如果…

InnoDB事務結構體代碼變量列表

事務結構 struct trx_t 寫在前面 InnoDB是MySQL的一個存儲引擎,支持事務,支持非堵塞的一致性讀,物理存儲結構是Page,每個事務都有回滾日志,重做日志,事務還會有死鎖檢測,各種各樣不同的鎖等等等…

對cookie與session的理解

cookie: 在網站中,http請求是無狀態的。也就是說即使第一次和服務器連接后并且登錄成功后,第二次請求服務器依然不能知道當前請求是哪個用戶。 cookie的出現就是為了解決這個問題, 第一次登錄后服務器返回一些數據(…

ubutun 更換網絡源_Ubuntu 更換源

1.切換到root用戶# su root備份源文件 目錄:/etc/apt# cd /etc/apt/# cp sources.list sources.list.bk3.更換源 阿里源 清華源# >sources.list # 清空源# vim sources.list # 選擇一個源,復制進去# apt update # 更新源,需要等幾分鐘# ex…

php : 常用函數

常用函數&#xff1a; <?php /*** 獲取客戶端IP* return [string] [description]*/ function getClientIp() {$ip NULL;if (isset($_SERVER[HTTP_X_FORWARDED_FOR])) {$arr explode(,, $_SERVER[HTTP_X_FORWARDED_FOR]);$pos array_search(unknown,$arr);if(false ! $po…

java日歷類add方法_Java日歷setFirstDayOfWeek()方法與示例

java日歷類add方法日歷類setFirstDayOfWeek()方法 (Calendar Class setFirstDayOfWeek() method) setFirstDayOfWeek() method is available in java.util package. setFirstDayOfWeek()方法在java.util包中可用。 setFirstDayOfWeek() method is used to sets the first day o…

zabbix監控部署 與添加主機

zabbix介紹&#xff1a; zabbix&#xff08;[zbiks]&#xff09;是一個基于WEB界面的提供分布式系統監視以及網絡監視功能的企業級的開源解決方案。zabbix能監視各種網絡參數&#xff0c;保證服務器系統的安全運營&#xff1b;并提供靈活的通知機制以讓系統管理員快速定位/解決…

線段樹 洛谷 p1531 I hate it(I hate it too)

這里寫鏈接內容 線段樹模板 字符串是一個很詭異的問題。。。。 #include<cstdio> #include<iostream> #include<string> #define q 200000 using namespace std; int a[q5],s[q<<25]; void bu(int o,int l,int r)//建樹 {if(lr){s[o]a[r];} else{int…

打開是什么樣子的圖片_情侶頭像 | 無論是什么樣子的你 我都好喜歡

點擊【情侶圖片大全】- 右上角找到【…】立刻設我為星標/置頂 - 不迷路哦情侶圖片大全“時光真瘋狂&#xff0c;我一路執迷與匆忙”情侶/閨蜜/動漫/閨蜜網名長按圖片保存 點擊圖片放大圖片高清&#xff0c;建議在 W i f i 下瀏覽這個世界是多么神奇我竟然遇見了你無論是什么…

Java File類File [] listFiles()方法(帶示例)

File類File [] listFiles() (File Class File[] listFiles()) This method is available in package java.io.File.listFiles(). 軟件包java.io.File.listFiles()中提供了此方法。 This method is used to return the names of all the files in the form of an array of files…

zabbix監控平臺添加服務(http,nginx,mysql)

1 . 監控httpd服務&#xff1a; 首先確保已經搭建zabbix監控平臺&#xff0c;并且將需要監控的主機已經添加。 對主機server2 上的http服務進行監控&#xff0c;首先確保server2主機安裝了http服務。 使用http在zabbix中自帶監控模版 點擊配置->主機->server2->模…

java為什么要重寫hashCode和equals方法

如果不被重寫&#xff08;原生&#xff09;的hashCode和equals是什么樣的&#xff1f;不被重寫&#xff08;原生&#xff09;的hashCode值是根據內存地址換算出來的一個值。 不被重寫&#xff08;原生&#xff09;的equals方法是嚴格判斷一個對象是否相等的方法&#xff0…

stl中map函數_map :: max_size()函數,以及C ++ STL中的Example

stl中map函數C STL映射:: max_size() (C STL map::max_size() ) It returns the maximum number of elements the container(map) is able to hold but at runtime, the size of the container may be limited to a value smaller than specified by max_size() by the amount…