Re: [問題] system.out.flush()必要嗎??

看板java作者 ( )時間18年前 (2007/04/25 16:03), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/2 (看更多)
Java API doc 中 java.io.PrintStream 最前面的介紹 the flush method is automatically invoked after a byte array is written, one of the println methods is invoked, or a newline character or byte ('\n') is written. ※ 引述《HeyScng ( )》之銘言: : import java.io.*; : public class Keyboard : { : public static void main(String args[]) throws Exception : { : BufferedReader br=new BufferedReader( : new InputStreamReader(System.in)); : String line; : System.out.print("請輸入一個字串: "); : System.out.flush(); : ^^^^^^^^^^^^^^^^^^^ : . : . : . : 書上寫 System.out.flush() 為強迫出清緩衝器而將字串輸出至螢幕 : 但是在這個程式中就算不清空亦可 : 所以我的問題來了 在system.out情況下 如果不flush可能有錯 : 我只看過C中緩衝器的概念:我記得是這樣的 : input 34 後執行 c1=getchar() c2=getchar() 此時c1=3 c2=4 : 但若為 輸入345時 執行 c1=getchar() c2=getchar() : 若不清空緩衝器 當再次input 1時 執行getchar() 得出的卻為5 不為 1 : 所以我的問題是在什麼情況情況下 如果不flush可能有錯!! : 或是只是要釋放緩衝器空間而已 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 125.233.247.211
文章代碼(AID): #16BmjbaC (java)
文章代碼(AID): #16BmjbaC (java)