Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

java.io.FileWriter + flush()

807591May 14 2008 — edited May 15 2008
I am using a FileWriter within my web app to log application events. After every write I do a flush().

The problem is the writes usually don't show up in the log file until I shutdown Tomcat. If I switch from using flush() to closing + reopening the FileWriter that fixes the issue, however that seems excessive and inefficient.

I don't mind waiting a few seconds for log messages to show up, but often the messages aren't showing up 30 minutes later, and this makes my logging near useless.

Why would flush() not do what it says? Is there a better alternative than completely closing/reopening the FileWriter? I am not using BufferedWriter or anything else. I'm using FileWriter directly.

JVM: 1.6.0_05-b13
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 12 2008
Added on May 14 2008
5 comments
795 views