国产探花免费观看_亚洲丰满少妇自慰呻吟_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教程頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 濉溪县| 沭阳县| 疏附县| 东乡| 焉耆| 华亭县| 正定县| 东方市| 西充县| 仙居县| 天全县| 德令哈市| 蛟河市| 宿迁市| 宁陵县| 菏泽市| 德庆县| 东明县| 平定县| 永登县| 肇源县| 中卫市| 安阳县| 乡城县| 义乌市| 马龙县| 青河县| 响水县| 临泉县| 江川县| 禄丰县| 巴塘县| 普宁市| 资中县| 阳新县| 平利县| 顺昌县| 马关县| 康定县| 马关县| 吉首市|