This week's book giveaway is in the Open Source Projects forum. We're giving away four copies of Eclipse Collections Categorically: Level up your programming game and have Donald Raab on-line! See this thread for details.
Note close calls flush, so calling both is redundant. I would always call close. I'm not sure what happens in your code if an exception is thrown. It may make sense to call close in a finally clause.
steve souza wrote:Note close calls flush, so calling both is redundant. I would always call close. I'm not sure what happens in your code if an exception is thrown. It may make sense to call close in a finally clause.
The method fw.close calls the method close from OutputStreamWriter class. Although OutputStreamWriter extends the Writer class, it overrides the close method, and its method don't call flush.
If you absolutely, positively HAVE to ensure it got written, call flush(). You can call flush anytime and you can call it as often as you like. If there's nothing to flush, the overhead is minimal.
Experience keeps a dear School, but Fools will learn in no other.
---
Benjamin Franklin - Postal official and Weather observer
PI day is 3.14 (march 14th) and is also einstein's birthday. And this is merely a tiny ad: