Can someone please explain why we we would use system.out.flush()
in a simpler way? If there could be a chance of losing data, please provide me with an example. If you comment it in the code below nothing changes!
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);
}
}
}
Thank you
PrintStream
do notflush
by default. – Jones