File System
Hello,
i have a simple problem, i think.....
I want to display the actual file system in a JTree like in the window explorer. Have someone a sample how it works ?
Can somebody give me a hint because i'm new in Java ?
How can i get the Drive letters and the directories and the files. Is there a possibility to get only for example *.jpg files ?
Thanx for help
Tom
[414 byte] By [
TZ007] at [2007-9-26 2:37:28]

this will give you the available file system roots.
File[] rootDirs = File.listRoots();
for( int i = 0; i < rootDirs.length; i++ ) {
System.out.println("[" + i + "]: " + rootDirs[i].getAbsolutePath());
}
this class can be used as a filter.
class JPEGFilter implements FilenameFilter {
public boolean accept( File dir, String name ) {
if( name.endsWith(".jpeg") || name.endsWith(".jpg") ) {
return true;
}
else {
return false;
}
}
}
this snippet gives you a list of File objects that satisfy the jpeg filter in a particular directory
File dir = new File("d:\\psarkar\\java\\programs\\rixml");
File[] files = dir.listFiles( new JPEGFilter() );
for( int i = 0; i < files.length; i++ ) {
System.out.println("[" + i + "]: " + files[i].getAbsolutePath());
}