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
tia_kamakshiAsked:
Who is Participating?
 
objectsConnect With a Mentor Commented:
> But I wanted to know the time in minutes.

long minutes = age / 60000;

0
 
CEHJCommented:
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
0
 
objectsCommented:
you can't get a files creation date with java so you'll need to use exec() of jni to do that

0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

 
objectsCommented:
if you mean since it was last modified then use

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

0
 
objectsCommented:
some code in here that may be of use

http://mindprod.com/products1.html#FILETIMES
0
 
tia_kamakshiAuthor Commented:
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
0
 
tia_kamakshiAuthor Commented:
Many Thanks.

I will check and come back to you.

Thanks again
0
 
tia_kamakshiAuthor Commented:
Many Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.