dcsimg
How to check for a file and if it exists, append to it; otherwise, create and write to it?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Aileen_Chen
Posted On:   Wednesday, March 21, 2001 06:40 PM

I am creating a log file to write out messages from a java program. However, since this java program will be running more than once a day, I would like to have just one log file per day. Therefore, I'd like to first check for a file if it exists for that day, and if it doesn't exist, then create the file and write to it. But if the file DOES exist, then I want to append to the file and keep the data previously written to it.

Re: How to check for a file and if it exists, append to it; otherwise, create and write to it?

Posted By:   AlessandroA_Garbagnati  
Posted On:   Saturday, March 31, 2001 11:30 PM

Aileen,

You can use java.io.FileWriter or java.io.FileOutputStream.

If you check the java documentation for that you'll see that both have a constructor that will allow you to pass an 'append' flag.
About | Sitemap | Contact