This week's book giveaway is in the Big Data forum.
We're giving away four copies of Elasticsearch in Action and have Radu Gheorghe & Matthew Lee Hinman on-line!
See this thread for details.
The moose likes I/O and Streams and the fly likes Unexpected Behaviour with Writers Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Elasticsearch in Action this week in the Big Data forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Unexpected Behaviour with Writers" Watch "Unexpected Behaviour with Writers" New topic

Unexpected Behaviour with Writers

jean-gobert de coster
Ranch Hand

Joined: Dec 04, 2008
Posts: 49
Hi, I'm running he following code:

And when I run it, the output is the following:

Hello!I'm a FileWriter
I'm a BufferedWriter
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42954
Why is that unexpected behavior? The buffered writer buffers its output, while the straight writer writes immediately. Seems like it should be.

As an aside, I wouldn't use several writers that access the same underlying resource.
jean-gobert de coster
Ranch Hand

Joined: Dec 04, 2008
Posts: 49
Ah ok... Buffered... figures :-) By Unexpected, I meant "that I didn't expect" of course. Thanks for the answer
I agree. Here's the link:
subject: Unexpected Behaviour with Writers