国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > Java > 正文

IO中flush()函數的使用代碼示例

2024-07-13 10:16:14
字體:
來源:轉載
供稿:網友

The javascript/60843.html">java.ios/298414.html">io.Writer.flush() method flushes the stream. If the stream has saved any characters from the various write() methods in a buffer, write them immediately to their intended destination. Then, if that destination is another character or byte stream, flush it. Thus one flush() invocation will flush all the buffers in a chain of Writers and OutputStreams.

public class Demo {	public static void main(String[] ars) throws Exception {		System.out.println("hello");		PrintWriter writer = new PrintWriter(System.out);		writer.println("writer start");		//   writer.flush();		try {			Thread.sleep(3000);		}		catch (InterruptedException e) {			// TODO Auto-generated catch block			e.printStackTrace();		}		writer.println("writer close");		writer.close();	}}

如上面代碼,如果flush()被注釋掉,則打印完“hello”之后3秒才會打印”writer start”,”writer close”,因為writer.close()在關閉輸出流前會調用一次flush()。效果如下:

java,io,flush,io流flush,字符流flush

如果flush()沒有被注釋掉,則則打印完“hello”之后會立即打印”writer start”。

java,io,flush,io流flush,字符流flush

總結

以上就是本文關于IO中flush()函數的使用代碼示例的全部內容,希望對大家有所幫助。感興趣的朋友可以繼續參閱本站其他相關專題,如有不足之處,歡迎留言指出。感謝朋友們對本站的支持!


注:相關教程知識閱讀請移步到JAVA教程頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 三台县| 福鼎市| 民乐县| 聂拉木县| 揭西县| 东台市| 丹巴县| 黄冈市| 天全县| 启东市| 中卫市| 宁德市| 眉山市| 孙吴县| 泾川县| 龙门县| 清远市| 临武县| 江陵县| 龙岩市| 阿荣旗| 惠东县| 韶山市| 武陟县| 山东| 含山县| 甘肃省| 根河市| 星子县| 洞口县| 晋江市| 洛宁县| 喀什市| 阿图什市| 林口县| 龙海市| 仪征市| 丹棱县| 乌兰县| 滕州市| 会东县|