有人能解释为什么我们会以更简单的方式使用system.out.flush()
?如果有可能丢失数据,请给我一个例子。如果你在下面的代码中评论它,没有什么改变!为什么我们使用system.out.flush()?
class ReverseApp{
public static void main(String[] args) throws IOException{
String input, output;
while(true){
System.out.print("Enter a string: ");
System.out.flush();
input = getString(); // read a string from kbd
if(input.equals("")) // quit if [Enter]
break;
// make a Reverser
Reverser theReverser = new Reverser(input);
output = theReverser.doRev(); // use it
System.out.println("Reversed: " + output);
}
}
}
谢谢
默认情况下'PrintStream'的某些方法不会'flush'。 –
http://stackoverflow.com/questions/7166328/when-why-to-call-system-out-flush-in-java – DT7