?
Solved

FInding file age in Java

Posted on 2009-02-22
8
Medium Priority
?
531 Views
Last Modified: 2012-05-06
Hi,

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

Please guide

Many Thanks
0
Comment
Question by:tia_kamakshi
  • 4
  • 3
8 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 23706833
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
 
LVL 92

Expert Comment

by:objects
ID: 23706839
you can't get a files creation date with java so you'll need to use exec() of jni to do that

0
 
LVL 92

Expert Comment

by:objects
ID: 23706844
if you mean since it was last modified then use

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

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 92

Expert Comment

by:objects
ID: 23706856
some code in here that may be of use

http://mindprod.com/products1.html#FILETIMES
0
 

Author Comment

by:tia_kamakshi
ID: 23707086
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
 
LVL 92

Accepted Solution

by:
objects earned 2000 total points
ID: 23707088
> But I wanted to know the time in minutes.

long minutes = age / 60000;

0
 

Author Comment

by:tia_kamakshi
ID: 23709415
Many Thanks.

I will check and come back to you.

Thanks again
0
 

Author Closing Comment

by:tia_kamakshi
ID: 31549870
Many Thanks
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses
Course of the Month16 days, 1 hour left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question