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

Size Range 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.sizeRangeFileFilter() API. It returns a filter that returns TRUE if the file size is within the given range.


File Name  :  
com/bethecoder/tutorials/commons_io/tests/filters/SizeRangeFilterTest.java 
Author  :  Sudhakar KV
Email  :  kvenkatasudhakar@gmail.com
   
package com.bethecoder.tutorials.commons_io.tests.filters;

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

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

public class SizeRangeFilterTest {

  /**
   @param args
   @throws IOException 
   */
  public static void main(String[] args) {
    File directory = new File("C:/input");
    
    File[] files = directory.listFiles((FileFilter)
        FileFilterUtils.sizeRangeFileFilter(01024));
        //Range in bytes inclusive
    
     for (File file : files) {
         System.out.println(file + " " + file.length() " byte(s)");
     }
  }
}
   

It gives the following output,
C:\input\db.png 547 byte(s)
C:\input\hidden_file.txt 1 byte(s)
C:\input\readonly_file.txt 1 byte(s)
C:\input\writable_file.txt 1 byte(s)


                    Print

   



Books Recommendation

 
 
bl  br