Java ObjectOutputStream writeLong()方法與示例

ObjectOutputStream類writeLong()方法 (ObjectOutputStream Class writeLong() method)

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

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

  • writeLong() method is used to write the given 8 bytes long value.

    writeLong()方法用于寫入給定的8個字節長的值。

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

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

  • writeLong() method may throw an exception at the time of writing long.

    writeLong()方法在寫入很長時間時可能會引發異常。

    IOException: This exception may throw when getting any input/output error while writing to the output stream.

    IOException :在寫入輸出流時遇到任何輸入/輸出錯誤時,可能引發此異常。

Syntax:

句法:

    public void writeLong(long value);

Parameter(s):

參數:

  • long value – represents the long value to be written.

    long value –表示要寫入的long值。

Return value:

返回值:

The return type of the method is void, it returns nothing.

該方法的返回類型為void ,不返回任何內容。

Example:

例:

// Java program to demonstrate the example 
// of void writeLong(long value) method of 
// ObjectOutputStream
import java.io.*;
public class WriteLongOfOOS {
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 the long to the stream		
obj_out_stm.writeLong(5411489332534l);
obj_out_stm.writeLong(234773224114l);
obj_out_stm.flush();
// By using readLong() method is to 
// read the long and convert it into long
for (int i = 0; i < 2; ++i) {
long l = (long) obj_in_stm.readLong();
System.out.println("obj_in_stm.readLong(): " + l);
}
// By using close() method is to 
// close all the streams 
System.out.println("Stream Shutdown...");
file_in_stm.close();
file_out_stm.close();
obj_in_stm.close();
obj_out_stm.close();
}
}

Output

輸出量

obj_in_stm.readLong(): 5411489332534
obj_in_stm.readLong(): 234773224114
Stream Shutdown...

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

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

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

相關文章

淺談Jfinal急速開發框架

2019獨角獸企業重金招聘Python工程師標準>>> 使用Jfinal一段時間了,記得當初14年吧,為了建立一個簡單的門戶網站,想找個輕量型的急速開發框架,然后搜到Jfinal,然后用了一段時間后,確實不錯, 現在吧,隨著時間的推移,作者對JFinal的版本迭代也是一直在努力,一直朝著優…

make 怎么降級_Ubuntu 中將 make 的版本降低

最新的 Ubuntu 版本使用的是 make 版本是 4.0.在編譯 Android4.4 源碼包時&#xff0c;由于 make 版本過高&#xff0c;命令提示行會提示編譯 Android4.4 源碼包需要 make 的版本為 3.81 或 3.82.build/core/main.mk:42: ****************************************************…

Java ObjectOutputStream writeChar()方法與示例

ObjectOutputStream類writeChar()方法 (ObjectOutputStream Class writeChar() method) writeChar() method is available in java.io package. writeChar()方法在java.io包中可用。 writeChar() method is used to write 2 bytes of a character value. writeChar()方法用于寫…

虛擬機的管理

我們采用虛擬機的原因是什么呢&#xff0c;很簡單就倆字&#xff1a; 節能 1. 管理虛擬機的命令&#xff1a; virt-manager開啟虛擬機管理器virsh list顯示正在運行的虛擬機virsh list --all查看所有虛擬機virsh start desktop打開虛擬機virsh shutdown desktop正常關閉虛擬機…

mybatis對java自定義注解的使用——入門篇

轉自&#xff1b;https://www.cnblogs.com/sonofelice/p/4980161.html 1. 最近在學習spring和ibatis框架。 以前在天貓實習時做過的一個小項目用到的mybatis&#xff0c;在其使用過程中&#xff0c;不加思索的用了比較原始的一種持久化方式&#xff1a; 在一個包中寫一個DAO的接…

Java BigDecimal toBigIntegerExact()方法(帶示例)

BigDecimal類的toBigIntegerExact()方法 (BigDecimal Class toBigIntegerExact() method) toBigIntegerExact() method is available in java.math package. toBigIntegerExact()方法在java.math包中可用。 toBigIntegerExact() method is used to convert this BigDecimal int…

Linux中的軟件管理

1. 使用已有的網絡安裝資源安裝軟件 cd /etc/yum.repos.d/ (移動到yum源指向的文件配置目錄下&#xff09; vim westos.repo &#xff08;新建文件&#xff0c;yum下后綴必須為.repo) 編輯這個文件里面寫 [redhat] &#xff08;軟件倉庫名稱&#xff09; namefirefox &#x…

楚留香ai人臉識別_戴口罩居然也能人臉識別?這些AI黑科技真的藏不住了.........

當人工智能遇見影像技術&#xff0c;將會釋放出多少意想不到的巨大能量&#xff1f;「喔圖知圖實驗室」瞄準當下的影像痛點&#xff0c;持續發力升級AI黑科技&#xff0c;帶來兩大必殺技——人臉識別再度升級、AI智能旋轉校正。戴口罩也能識別——人臉識別升級戴口罩人臉識別如…

android--------Popupwindow的使用

2019獨角獸企業重金招聘Python工程師標準>>> PopupWindow在Android.widget包下&#xff0c;項目中經常會使用到PopupWindow做菜單選項&#xff0c; PopupWindow這個類用來實現一個彈出框&#xff0c;可以使用任意布局的View作為其內容&#xff0c;這個彈出框是懸浮…

使用JavaScript中的示例的escape()函數

While transferring the data over the network or sometimes while saving data to the database, we need to encode the data. The function escape() is a predefined function in JavaScript, which encodes the given string. 在通過網絡傳輸數據或有時將數據保存到數據庫…

安裝虛擬機的腳本

1. 先安裝生成自動安裝腳本的工具 yum install system-config-kickstart -y 2. 打開這個軟件 system-config-kickstart 基本設置&#xff1a;更改時區為上海&#xff0c;設置root用戶密碼 2&#xff09;設置安裝方法為網絡安裝&#xff0c;將共享的鏡像文件地址正確填寫 3&…

小小小游戲

寫著玩 FlappyBird 視頻:https://pan.baidu.com/s/1sljIR5z 游戲:https://pan.baidu.com/s/1ge8j7Ej 項目:https://pan.baidu.com/s/1eSysxpw Breakout 視頻:https://pan.baidu.com/s/1gfhv4hd 項目:https://pan.baidu.com/s/1hs8xPly QBert 視頻:https://pan.baidu.com/s/1s…

go在方法中修改結構體的值_[Go]結構體及其方法

結構體類型可以包含若干字段&#xff0c;每個字段通常都需要有確切的名字和類型。也可以不包含任何字段&#xff0c;這樣并不是沒有意義的&#xff0c;因為還可以為這些類型關聯上一些方法&#xff0c;這里可以把方法看作事函數的特殊版本。函數事獨立的程序實體&#xff0c;可…

to_number用法示例_Number()函數以及JavaScript中的示例

to_number用法示例Number()函數 (Number() function) Number() function is a predefined global function in JavaScript, it used to convert an object to the number. If the function is not able to convert the object in a number – it returns "NaN". (Rea…

系統延時任務及定時任務

1. 系統延時任務&#xff1a; at相關命令 at time 設定任務執行時間at> rm -fr /mnt/* 任務動作at> <EOT> <<ctrld 執行任務at的命令&#xff1a; -l ##查看任務列表-c …

cpn tools查看運行時間_Jmeter在Linux下的運行測試

一、JMeterApache JMeter是Apache組織開發的基于Java的壓力測試工具。用于對軟件做壓力測試&#xff0c;它最初被設計用于Web應用測試&#xff0c;但后來擴展到其他測試領域。1.1、JMeter的作用能夠對HTTP和FTP服務器進行壓力和性能測試&#xff0c; 也可以對任何數據庫進行同樣…

css div滾動_如何使用CSS創建可垂直滾動的div?

css div滾動Introduction: 介紹&#xff1a; Dealing with divs has become a regularity and divs are used for many purposes like to structure our code and to segregate our various sections of codes. Besides, we are also aware of many properties that we can im…

Linux中磁盤分區的管理

1. 本地存儲設備的識別 fdisk -l真實存在的設備cat /proc/partitions系統識別的設備blkid系統可使用的設備df系統正在掛載的設備 真實存在的設備不一定可識別&#xff0c;識別到的的設備不一定可使用 2. 設備的掛載和卸載 1&#xff09;設備名稱 /dev/xdx …

python中時間的加減_python日期加減

python中關于時間和日期函數的常用計算總結 python中關于時間和日期函數有time和datatime 1.獲取當前時間的兩種方法: import datetime,time now = time.strftime("%Y-%m-%d %H:%M:%S") print now now = datetime.datetime.now()... 文章 技術小胖子 2017-11-08 848…

bst 刪除節點_在BST中刪除大于或等于k的節點

bst 刪除節點Problem statement: 問題陳述&#xff1a; Given a BST and a value x, write a function to delete the nodes having values greater than or equal to x. The function will return the modified root. 給定一個BST和一個值x &#xff0c;編寫一個函數刪除值大…