Java ObjectOutputStream flush()方法與示例

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

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

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

  • flush() method is used to flush this stream and write bytes immediately of any buffered output to the underlying stream.

    flush()方法用于刷新此流,并將任何緩沖輸出的字節立即寫入基礎流。

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

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

  • flush() method may throw an exception at the time of flushing the stream.

    flush()方法在刷新流時可能會引發異常。

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

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

Syntax:

句法:

    public void flush();

Parameter(s):

參數:

  • It does not accept any parameter.

    它不接受任何參數。

Return value:

返回值:

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

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

Example:

例:

// Java program to demonstrate the example 
// of void flush() method of ObjectOutputStream
import java.io.*;
public class FlushOfOOS {
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 writeByte() method is to
// write byte to the stream		
obj_out_stm.writeByte(65);
// By using flush() method is to
// flush the stream immediately
System.out.println("Stream Flushed...");
obj_out_stm.flush();
// By using readByte() method is to 
// read the byte and convert it into
// char
char ch = (char) obj_in_stm.read();
System.out.println("ch: " + ch + " ");
// 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

輸出量

Stream Flushed...
ch: A 
Stream Shutdown... 

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

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

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

相關文章

ffmpeg 命令裁剪合并

1 mp4格式: 裁剪從一個視頻中的1分鐘、2分鐘、3分鐘開始截取10秒 ffmpeg -i test_1280x720.mp4 -ss 00:01:00 -t 10 -codec copy copy1.mp4 ffmpeg -i test_1280x720.mp4 -ss 00:02:00 -t 10 -codec copy copy2.mp4 ffmpeg -i test_1280x720.mp4 -ss 00:03:00 -t 10…

Struts2初始化流程及源碼分析

1.1 Struts2初始化 在講Struts2的初始化之前,應該為大家描述下Web應用中的過濾器Filter,這關系到我們對核心過濾器FilterDispatcher的正確理解。 Filter:一個filter是一個對象,為每個請求資源(一個servlet或靜態內容) &#xff0c…

實驗1 數據庫操作

實驗1 數據庫操作一、實驗目的 1.掌握管理工具、T-SQL創建數據庫的方法。 2.掌握管理工具、T-SQL修改和查看數據庫的方法。 3.掌握管理工具、T-SQL刪除數據庫的方法。 4.掌握數據庫的附加與分離 二、實驗要求 1.創建實驗所用到的“網上購物系統”數據庫eshop。 三、實驗內容 1…

Java FileInputStream finalize()方法與示例

FileInputStream類的finalize()方法 (FileInputStream Class finalize() method) finalize() method is available in java.io package. finalize()方法在java.io包中可用。 finalize() method is used to assure that close() method of this FileInputStream invokes when th…

逆風飛揚,吳仁宏

摘自逆風飛揚,吳仁宏自傳 它是一個從"生而自卑"到"個性飛揚"的故事,當然具有傳奇色彩 中國人幾千年都不是天生的贏家,讓我們努力,為國為家為自己,做贏家! 生存哲學 尼采 痛苦,挫折使生命遷長,使人…

ffmpeg 命令圖片和視頻相互轉換

1當前文件環境: ffmpeg -i test.mp4 -y -f image2 -ss 00:00:02 -vframes 1 -s 640x360 test.jpg ffmpeg -i test.mp4 -y -f image2 -ss 00:00:02 -vframes 1 -s 640x360 test.bmp 使用ffplay test.jpb ffplay test.bmp 都是可以打開的 參數介紹: -y 如…

如何點擊鏈接直接跳轉到app store指定應用下載頁面

轉載自:http://blog.csdn.net/zengconggen/article/details/6789420 NSString *str [NSString stringWithFormat:"http://itunes.apple.com/us/app/id%d", 436957167]; [[UIApplication sharedApplication] openURL:[NSURL urlWithString:str]];其中&…

COLLEGE.sql(復制的時候注意路徑!!!)

USE [master] GO /****** Object: Database [COLLEGE] Script Date: 2019/11/25 星期一 上午 08:57:11 / CREATE DATABASE [COLLEGE] ON PRIMARY ( NAME N’COLLEGE_m’, FILENAME N’F:\COLLEGE\COLLEGE.mdf’ , SIZE 51200KB , MAXSIZE UNLIMITED, FILEGROWTH 10240KB )…

【管理】「本能叛逆」與「理性叛逆」

叛逆是一般人認知的負面名詞,但是,很多人都忽略掉,它卻是人類進步的重要因子。觀察孩童的成長過程,十歲以后都會出現叛逆行為,相當令父母及師長頭痛。然而,叛逆卻是促使孩童突破家庭單一環境養成的認知與觀…

Java Double類parseDouble()方法的示例

Double類parseDouble()方法 (Double class parseDouble() method) parseDouble() method is available in java.lang package. parseDouble()方法在java.lang包中可用。 parseDouble() method is used to return the double value corresponding to the given String or in oth…

ffmpeg命令 拉流

1: 拉流播放:rtmp (ffplay rtmp://server/live/streamName) ffplay -x 480 -y 320 rtmp://58.200.131.2:1935/livetv/cctv1 2: 拉流存儲到文件:rtmp ffmpeg -i rtmp://58.200.131.2:1935/livetv/cctv1 -codec copy cctvrtmp.f…

小心pthread_cond_signal和SetEvent之間的差異

ZZ FROM: http://blog.csdn.net/absurd/article/details/1402433 轉載時請注明出處和作者聯系方式&#xff1a;http://blog.csdn.net/absurd 作者聯系方式&#xff1a;Li XianJing <xianjimli at hotmail dot com> 更新時間&#xff1a;2006-12-19 今天幫同事查一個多線…

eshop.sql(復制的時候注意路徑!!!)

USE [master] GO /****** Object: Database [eshop] Script Date: 2019/11/25 星期一 上午 08:54:14 / CREATE DATABASE [eshop] ON PRIMARY ( NAME N’eshop_dat’, FILENAME N’D:\eshop\eshop_dat.mdf’ , SIZE 10240KB , MAXSIZE 51200KB , FILEGROWTH 5120KB ) LOG O…

doublevalue_Java Double類doubleValue()方法與示例

doublevalueDouble類doubleValue()方法 (Double class doubleValue() method) doubleValue() method is available in java.lang package. doubleValue()方法在java.lang包中可用。 doubleValue() method is used to return the value denoted by this Double object converted…

ffmpeg 命令過濾器裁剪

1 圖片操作&#xff1a; 原圖&#xff1a; 使用ffplay 顯示左半邊 ffplay -i input.png -vf cropiw/2:ih:0:0 可以通過ffmpeg 保存 ffmpeg -i input.png -vf cropiw/2:ih:0:0 out.png 2 視頻操作&#xff1a; 原視頻&#xff1a; 顯示左半邊 ffplay -i cctvhttp.flv -vf …

去除aspx生成的頁面最開始的空行

使用.aspx生成的頁面一般都會有一個或多個空行&#xff0c;當然這些空行不會影響頁面在瀏覽器中的渲染結果&#xff0c;不過在查看源代碼的時候感覺有些別扭&#xff0c;我曾試著去刪除這些空行&#xff0c;但沒有成功&#xff0c;你知道你們有沒有去嘗試。 1 <% Page Langu…

PUBLISH.sql(復制的時候注意路徑!!!)

USE [master] – GO – /****** Object: Database [PUBLISH] Script Date: 2019/11/25 星期一 上午 09:00:04 / – CREATE DATABASE [PUBLISH] ON PRIMARY – ( NAME N’PUBLISH’, FILENAME N’F:\PUBLISH\PUBLISH.mdf’ , SIZE 51200KB , MAXSIZE UNLIMITED, FILEGROWTH …

c ++ 函數的esp指針_在C ++中通過指針訪問成員函數

c 函數的esp指針Create a class along with data member and member functions and then access the member functions by using a pointer in C. 創建一個類以及數據成員和成員函數&#xff0c;然后使用C 中的指針訪問成員函數。 如何通過指針訪問成員函數&#xff1f; (How…

[iphone-cocos2d]分享一段Objective-C可調用的游戲中播放音樂(1)

首先需要引入AudioTool 這個framework 代碼 -(id)initWithPath:(NSString *)path{ UInt32 size, maxPacketSize; char*cookie; inti; if(gThereIsAnActiveTrack) { NSLog("*** WARNING *** GBMusicTrack only plays one track at a time…

匯編語言-010(循環移位ROL,ROR 、進位循環進位RCL,RCR 、有符號數溢出 、雙精度移位SHLD,SHRD、SHL和ADD計算 、位運算應用)

1 &#xff1a;循環移位ROL,ROR,帶進位循環進位RCL,RCR .386 .model flat,stdcall.stack 4096 ExitProcess PROTO,dwExitCode:DWORD.code main PROC;循環左移mov al,40h ;AL 010000000brol al,1 ;AL 100000000b ,CF 0rol al,1 ;AL 000000001b ,CF 1rol al,1 ;A…