KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > io > filefilter > DirectoryFileFilter


1 /*
2  * Copyright 2002-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.commons.io.filefilter;
17
18 import java.io.File JavaDoc;
19
20 /**
21  * This filter accepts <code>File</code>s that are directories.
22  * <p>
23  * For example, here is how to print out a list of the
24  * current directory's subdirectories:
25  *
26  * <pre>
27  * File dir = new File(".");
28  * String[] files = dir.list( DirectoryFileFilter.INSTANCE );
29  * for ( int i = 0; i &lt; files.length; i++ ) {
30  * System.out.println(files[i]);
31  * }
32  * </pre>
33  *
34  * @since Commons IO 1.0
35  * @version $Revision: 1.7 $ $Date: 2004/02/23 04:37:57 $
36  *
37  * @author Henri Yandell
38  * @author Stephen Colebourne
39  * @author Peter Donald
40  */

41 public class DirectoryFileFilter extends AbstractFileFilter {
42     
43     /** Singleton instance of directory filter */
44     public static final IOFileFilter INSTANCE = new DirectoryFileFilter();
45     
46     /**
47      * Restrictive consructor.
48      */

49     protected DirectoryFileFilter() {
50     }
51     
52     /**
53      * Checks to see if the file is a directory.
54      *
55      * @param file the File to check
56      * @return true if the file is a directory
57      */

58     public boolean accept(File JavaDoc file) {
59         return file.isDirectory();
60     }
61     
62 }
63
Popular Tags