Link to home
Start Free TrialLog in
Avatar of tia_kamakshi
tia_kamakshiFlag for United Arab Emirates

asked on

FInding file age in Java

Hi,

How do we check in Java that file age is more than 10 min or 5 min

Please guide

Many Thanks
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

What do you mean by age? If you mean when it was created, that's not possible to know via Java - not every OS has a record of when a file was created
you can't get a files creation date with java so you'll need to use exec() of jni to do that

if you mean since it was last modified then use

long age = new Date().getTime() - file.lastModified();

some code in here that may be of use

http://mindprod.com/products1.html#FILETIMES
Avatar of tia_kamakshi

ASKER

Hi,

Thanks for your responses.

I wanted to know the age of file, means when it was created or modified and the current time.

How many minutes, or hours has passed from the current time

Yes, this will help me
long age = new Date().getTime() - file.lastModified();

But I wanted to know the time in minutes.

Becuase there is a directory where XML file should not be present in there more than 5 min.
Some file should not be present there for more than 10 min

If file stays there in the directory than alert mail and sms needs to be sent immedieately

So, I wanted the minutes passed from the time file is created in the system or modified in the system.

I am very thankful to you and EE for providing great help

Thanks again
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Many Thanks.

I will check and come back to you.

Thanks again
Many Thanks