SizeFileFilterpublic class SizeFileFilter extends AbstractFileFilter implements SerializableFilters files based on size, can filter either smaller files or
files equal to or larger than a given threshold.
For example, to print all files and directories in the
current directory whose size is greater than 1 MB:
File dir = new File(".");
String[] files = dir.list( new SizeFileFilter(1024 * 1024) );
for ( int i = 0; i < files.length; i++ ) {
System.out.println(files[i]);
}
|
Fields Summary |
---|
private final long | sizeThe size threshold. | private final boolean | acceptLargerWhether the files accepted will be larger or smaller. |
Constructors Summary |
---|
public SizeFileFilter(long size)Constructs a new size file filter for files equal to or
larger than a certain size.
this(size, true);
| public SizeFileFilter(long size, boolean acceptLarger)Constructs a new size file filter for files based on a certain size
threshold.
if (size < 0) {
throw new IllegalArgumentException("The size must be non-negative");
}
this.size = size;
this.acceptLarger = acceptLarger;
|
Methods Summary |
---|
public boolean | accept(java.io.File file)Checks to see if the size of the file is favorable.
If size equals threshold and smaller files are required,
file IS NOT selected.
If size equals threshold and larger files are required,
file IS selected.
boolean smaller = file.length() < size;
return acceptLarger ? !smaller : smaller;
| public java.lang.String | toString()Provide a String representaion of this file filter.
String condition = acceptLarger ? ">=" : "<";
return super.toString() + "(" + condition + size + ")";
|
|