my dog learned polymorphism
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

Win a copy of Building Microservices this week in the Design forum!
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="" target="_blank" rel="nofollow"></a>
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: delete logfiles that are older than 3 months
It's not a secret anymore!