wood burning stoves*
The moose likes Beginning Java and the fly likes delete logfiles that are older than 3 months Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "delete logfiles that are older than 3 months" Watch "delete logfiles that are older than 3 months" New topic

delete logfiles that are older than 3 months

Angela Stempfel

Joined: Nov 27, 2001
Posts: 15
hi all
how can i check if i file is older than 3 months? i have to dates:
-the date when the logfile was created
- the current date
Paul Stevens
Ranch Hand

Joined: May 17, 2001
Posts: 2823
The lastModified() of File will return a long representing the date last modified. Convert that to a Date and do your check.
Jason Kretzer
Ranch Hand

Joined: May 31, 2001
Posts: 280
To expand a little on the previous post, first set up a constant that would hold the number of miliseconds in the three month period--approximately 90 days. Subtract this number from the current day's date which can be found using System.currentTimeMillis(). If the date of the file( from the lastModified() method of File) is less than the number just calculated above, then delete it; else keep it.
Hope this helps.

Jason R. Kretzer<br />Software Engineer<br />System Administrator<br /><a href="http://alia.iwarp.com" target="_blank" rel="nofollow">http://alia.iwarp.com</a>
wood burning stoves
subject: delete logfiles that are older than 3 months
Similar Threads
How to copy old data from one table to another in same database
Compare date cannot be greater than 12 months apart
When did you first feel 'old' (assuming you do)
Dirty math problem