You will be redirected to our new website in 5 seconds...
If you are not automatically taken to our new web site,
please click on the hyperlink :
http://jodd.org
Jodd
build: 309
updated: Jun 17 2008
 

SourceForge.net Logo

freebsd  Support this project

home Home | download | home Contact | SourceForge | File Releases releases | News news |  
FindFile

Finding files is a common task in developer's life. FindFile class may help: it searches path for files and folders. FindFile is configurable, so users may choose to perform recursive search for files and/or folders on one or more paths, as well as to choose if subfolders should be listed before files.

Subclasses of FindFile provide various matching mechanisms. Fastest one and, probably, most used is WildcardFindFile - uses wildcard patterns for matching files. Besides wildcards, available are: RegExpFindFile and FilterFindFile.

FindFile and its derivates work iterative and has to be used in the loop. Here is an simple example that finds all files on the classpath:

FindFile ff = new WildcardFindFile("*").recursive().includeDirs().searchPath(SystemUtil.getClassPath());
File f;
while ((f = ff.nextFile()) != null) {
	if (f.isDirectory() == true) {
		System.out.println(". >" + f.getName());
	} else {
		System.out.println(". " + f.getName());
	}
}

In the example, WildcardFindFile is used to match all files. Search is recursive, includes subfolders and will be performed on current system class path.

FindClass

Finding a class is a specific way of finding files. Similar to FindFile, FindClass provides an iterative way for finding classes, either on classpaths or in jar files. Because of different sources (File and Jar entry), FindClass is an abstract class with callback method that will be invoked on founded classes. More, it is possible to get InputStream of founded classes, if required.

FindClass is configurable, so users may fine-tune the search, what may be important when complete classpath is scanned. It is possible to specify included and excluded Jar files and/or included packages. Names are matched with wildcard templates.

FindClass is used by Jodd web framework, IOC container and database engine, for automatic configurations.