tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Tools and Libs > Commons IO > Filters > Age Filter

Age Filter 

Apache Commons IO is a java library with simple IO utilities and filters. This requires the library commons-io-2.1.jar to be in classpath. The following example shows using FileFilterUtils.ageFileFilter() API. It returns a filter that returns TRUE if the file's last modified time stamp is older than (before) the given cutoff date.


File Name  :  
com/bethecoder/tutorials/commons_io/tests/filters/AgeFilterTest.java 
Author  :  Sudhakar KV
Email  :  [email protected]
   
package com.bethecoder.tutorials.commons_io.tests.filters;

import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import java.util.Date;

import org.apache.commons.io.filefilter.FileFilterUtils;

public class AgeFilterTest {

  /**
   @param args
   @throws IOException 
   */
  public static void main(String[] args) {
    File directory = new File("C:/input");
    File refFile = new File("C:/input/db.png");

    //Files with modified date after the specified date
    File[] files = directory.listFiles((FileFilter)
        FileFilterUtils.ageFileFilter(new Date(refFile.lastModified())));

    System.out.println("Ref file TS : " new Date(refFile.lastModified()));

    for (File file : files) {
      System.out.println(file + " " new Date(file.lastModified()));
    }
  }
}
   

It gives the following output,
Ref file TS : Sun Oct 23 23:54:09 IST 2011

C:\input\console.png Sun Oct 23 23:54:09 IST 2011
C:\input\db.png Sun Oct 23 23:54:09 IST 2011
C:\input\one.css Mon Oct 03 17:32:02 IST 2011
C:\input\three.css Mon Oct 03 17:32:02 IST 2011
C:\input\two.css Mon Oct 03 17:32:02 IST 2011



 
  


  
bl  br