Java ObjectInputStream readLong()方法(帶示例)

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

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

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

  • readLong() method is used to read 8 bytes (i.e. 64 bit) of long value from this ObjectInputStream stream.

    readLong()方法用于從此ObjectInputStream流中讀取8個字節(即64位)的長值。

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

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

  • readLong() method may throw an exception at the time of reading long.

    readLong()方法在讀取較長時間時可能會引發異常。

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

Syntax:

句法:

    public long readLong();

Parameter(s):

參數:

  • It does not accept any parameter.

    它不接受任何參數。

Return value:

返回值:

The return type of the method is long, it returns the 8 bytes long value read.

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

Example:

例:

// Java program to demonstrate the example 
// of long readLong() method of ObjectInputStream
import java.io.*;
public class ReadLongOfOIS {
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 writeLong() method is to write
// long to the obj_out_stm stream
obj_out_stm.writeLong(5411489332534l);
obj_out_stm.writeLong(234773224114l);
obj_out_stm.flush();
while (obj_in_stm.available() > 0) {
// By using readLong() method is to read
//  long from the obj_in_stm
long val = (int) obj_in_stm.readLong();
System.out.println("obj_in_stm.readLong(): " + 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.readLong(): -169460426
obj_in_stm.readLong(): -1449977166

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

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

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

相關文章

交換瓶子(藍橋杯)

有N個瓶子,編號 1 ~ N,放在架子上。 比如有5個瓶子: 2 1 3 5 4 要求每次拿起2個瓶子,交換它們的位置。 經過若干次后,使得瓶子的序號為: 1 2 3 4 5 對于這么簡單的情況,顯然,至少…

Linux設備驅動開發---字符設備驅動程序

字符設備驅動程序1 主設備和次設備的概念設備號的注冊和釋放靜態方法動態方法區別2 設備文件操作struct file_operations與struct file、struct inode關系3 分配和注冊字符設備class_createcdev_adddevice_create4 字符設備驅動程序字符設備通過字符(一個接一個的字…

Java LinkedHashMap getOrDefault()方法與示例

LinkedHashMap類的getOrDefault()方法 (LinkedHashMap Class getOrDefault() method) getOrDefault() method is available in java.util package. getOrDefault()方法在java.util包中可用。 getOrDefault() method is used to get the value associated with the given key el…

Java中的異常棧軌跡和異常鏈

Java中允許對異常進行再次拋出,以提交給上一層進行處理,最為明顯的例子為Java的常規異常。 常規異常:有Java所定義的異常,不需要異常聲明,在未被try-catch的情況下,會被默認上報到main()方法。 Example: pu…

貪心算法---背包問題(物品可以分割問題)

問題背景: 有一天,阿里巴巴趕著一頭毛驢上山砍柴。砍好柴準備下山時,遠處突然出現一股煙塵,彌漫著直向上空飛揚,朝他這兒卷過來,而且越來越近。靠近以后,他才看清原來是一支馬隊,他…

同步---信號量

信號量1 信號量2 驅動程序和測試程序3 內核的具體實現總結1 信號量 Linux中的信號量是一種睡眠鎖。如果有一個任務試圖獲得一個已經被占用的信號量時,信號量會將其放到一個等待隊列,然后讓其睡眠,這時處理器去執行其他代碼。當持有信號量的進…

Java Float類floatToIntBits()方法與示例

Float類floatToIntBits()方法 (Float class floatToIntBits() method) floatToIntBits() method is available in java.lang package. floatToIntBits()方法在java.lang包中可用。 floatToIntBits() method follows IEEE 754 floating-point standards and according to standa…

解釋三度帶和六度帶的概念以及各坐標系如何定義

★ 地形圖坐標系:我國的地形圖采用高斯-克呂格平面直角坐標系。在該坐標系中,橫軸:赤道,用Y表示;縱軸:中央經線,用X表示;坐標原點:中央…

0-1背包問題(物品不可分割)

問題背景: 所謂“鐘點秘書”,是指年輕白領女性利用工余時間為客戶提供秘書服務,并按鐘點收取酬金。“鐘點秘書”為客戶提供有償服務的方式一般是:采用電話、電傳、上網等“遙控”式 服務,或親自到客戶公司處理部分業務…

算法---KMP算法

字符串1 KMP算法狀態機概述構建狀態轉移1 KMP算法 原文鏈接:https://zhuanlan.zhihu.com/p/83334559 先約定,本文用pat表示模式串,長度為M,txt表示文本串,長度為N,KMP算法是在txt中查找子串pat&#xff0…

cache初接觸,并利用了DataView

我們在寫代碼的時候,如果數據控件要獲得數據,一般方法,Conn.Open();OleDbCommand cmd;cmd new OleDbCommand(sql, Conn);GridView1.DataSource dbcenter.accessGetDataSet(sql);GridView1.DataBind();Conn.close();但如果多個數據控件要綁定數據,則比較頻繁打開數據庫,效率一…

Java ByteArrayInputStream reset()方法及示例

ByteArrayInputStream類reset()方法 (ByteArrayInputStream Class reset() method) reset() method is available in java.util package. reset()方法在java.util包中可用。 reset() method is used to reset this ByteArrayInputStream to the last time marked position and …

回文數猜想

問題描述: 一個正整數,如果從左向右讀(稱之為正序數)和從右向左讀(稱之為倒序數)是一樣的,這樣的數就叫回文數。任取一個正整數,如果不是回文數,將該數與他的倒序數相加…

文件上傳 帶進度條(多種風格)

文件上傳 帶進度條 多種風格 非常漂亮&#xff01; 友好的提示 以及上傳驗證&#xff01; 部分代碼&#xff1a; <form id"form1" runat"server"><asp:ScriptManager ID"scriptManager" runat"server" EnablePageMethods&quo…

同步---自旋鎖

1 自旋鎖的基本概念 自旋鎖最多只能被一個可執行線程持有&#xff0c;如果一個執行線程試圖獲得一個已經被使用的自旋鎖&#xff0c;那么該線程就會一直進行自旋&#xff0c;等待鎖重新可用。在任何時刻&#xff0c;自旋鎖都可以防止多余一個的執行線程同時進入臨界區。 Linu…

實習日志----4.播放時段參數設置

由于客戶在下發廣告時&#xff0c;一則廣告可在多個時段播放&#xff0c;這就需要設置多個播放時段的參數。 但在這種情況下&#xff0c;我并不知道用戶每次需要下發幾個時段&#xff0c;所以前臺不能設定死。 因此我要實現這么一個功能&#xff0c;讓用戶根據自己的需要來動態…

線性插值算法實現圖像_C程序實現插值搜索算法

線性插值算法實現圖像Problem: 問題&#xff1a; We are given an array arr[] with n elements and an element x to be searched amongst the elements of the array. 給定一個數組arr []&#xff0c;其中包含n個元素和一個要在該數組的元素中搜索的元素x 。 Solution: 解&…

hdu 1197

地址&#xff1a;http://acm.hdu.edu.cn/showproblem.php?pid1197 題意&#xff1a;求一個數轉換成10&#xff0c;12&#xff0c;16進制后各個位上的數的和是否相等。 mark&#xff1a;模擬進制轉換。 代碼&#xff1a; #include <stdio.h>int zh(int a, int n) {int su…

linux系統編程---線程總結

線程總結1 線程的實現線程創建線程退出線程等待線程清理2 線程的屬性線程的分離線程的棧地址線程棧大小線程的調度策略線程優先級3 線程的同步互斥鎖讀寫鎖條件變量信號量線程是系統獨立調度和分配的基本單位。同一進程中的多個線程將共享該進程中的全部系統資源&#xff0c;例…

博客上一些項目相關源碼鏈接

GitHub&#xff1a;https://github.com/beyondyanyu/Sayingyy