StringWriter has a flush function. What does it mean to flush a string buffer?
Asked
Active
Viewed 5,426 times
2 Answers
26
It must have an implementation of flush()
because in its superclass Writer
that's an abstract method, and StringWriter
is not an abstract class. However, if you look at the source code of StringWriter.flush()
, which you can find in the file src.zip
in your JDK installation directory, you'll see:
/**
* Flush the stream.
*/
public void flush() {
}
In other words, it does nothing. (There are ofcourse other subclasses of Writer
where flush()
does do something useful).
The person who implemented this method could have documented that it doesn't do anything, but they didn't.

Jesper
- 202,709
- 46
- 318
- 350
-
@mishadoff For that, see the answers by others on your question. Also the API documentation of `java.io.Writer.flush()` explains what this method is for. – Jesper Sep 20 '12 at 08:14
-
I mean exact this implementation of `flush` :) – mishadoff Sep 20 '12 at 08:14
-
9@mishadoff As you see, it does nothing. What's to not understand about that? – Jesper Sep 20 '12 at 08:15
2
In general a flush forces a buffer to write its content to the destination, for example writing the bytes to the file on the harddisk.

Stefan
- 2,603
- 2
- 33
- 62
-
-
1
-
2You didn't make it into an answer to OP's question, though. We can safely assume this is what OP knows and is in fact the reason why he asked the question. – Marko Topolnik Sep 20 '12 at 09:17