Re: [問題] system.out.flush()必要嗎??
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
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):