AllExperts > Experts 
Search      

Java

Volunteer
Answers to thousands of questions
 Home · More Questions · Answer Library  · Encyclopedia ·
More Java Answers
Question Library

Ask a question about Java
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About Neal Ziring
Expertise
Almost anything about the core Java platform, with an emphasis on networking. Not familiar with JDBC or the new Java graphics APIs. [Sun Certified Java Programmer, JDK 1.1]

Experience
Certified Java Programmer for JDK 1.1 and 2.0.
 
   

You are here:  Experts > Computing/Technology > Focus on Java > Java > deletion of folder

Topic: Java



Expert: Neal Ziring
Date: 5/27/2008
Subject: deletion of folder

Question
i am working on a project where i have to delete the folder after 7 days.can you please tell me a program(code in java) which can delete the folder when it is 7 days old.

Answer
Swati,

Java provides a class that will do most of what you need:
java.io.File.  It allows you to check the modification date
of a file, and it allows you to delete files.

For example, given a file path, here is some code that
tells you how "old" the file is in days.

  public float fileAge(String path) throws IOException {
      File myfile;
      myfile = new File(path);
      long mtime;
      mtime = myfile.lastModified();
      long now;
      now = System.currentTimeMillis();
      long age;
      age = now - mtime;
      return (age / (1000.0 * 60 * 60 * 24));
  }


Now, if you want to delete a file, you need to create a File
object, and call its delete() method.

For more information, check the JDK documentation for the
java.io.File object.

...nz  

Add to this Answer    Ask a Question



  Rate this Answer
   Was this answer helpful?
Not at allDefinitely              
   12345  

     
About Us | Advertise on This Site | User Agreement | Privacy Policy | Help
Copyright  © 2008 About, Inc. About and About.com are registered trademarks of About, Inc. The About logo is a trademark of About, Inc. All rights reserved.