read multiple files from a directory

Hello,I'm wondering how I can read load/read all the files from a certain directory without knowing their names.Can I somehow load them one by one and process them?Regards,Pesho
[213 byte] By [Pesho_318ia] at [2007-11-26 21:09:56]
# 1

File dir = new File("directoryName");

String[] children = dir.list();

if (children == null) {

// Either dir does not exist or is not a directory

} else {

for (int i=0; i<children.length; i++) {

// Get filename of file or directory

String filename = children[i];

}

}

// It is also possible to filter the list of returned files.

// This example does not return any files that start with `.'.

FilenameFilter filter = new FilenameFilter() {

public boolean accept(File dir, String name) {

return !name.startsWith(".");

}

};

children = dir.list(filter);

// The list of files can also be retrieved as File objects

File[] files = dir.listFiles();

// This filter only returns directories

FileFilter fileFilter = new FileFilter() {

public boolean accept(File file) {

return file.isDirectory();

}

};

files = dir.listFiles(fileFilter);

>

java_2006a at 2007-7-10 2:46:06 > top of Java-index,Java Essentials,Java Programming...
# 2
Thanks !
Pesho_318ia at 2007-7-10 2:46:06 > top of Java-index,Java Essentials,Java Programming...