I prefer Commons VFS . It can handle local file systems, SFTP and many others. All with the same code - you just change the file paths.
FileSystemManager fsManager = VFS.getManager();
FileObject directory = fsManager.resolveFile("path/to/dir");
FileObject[] files = directory.findFiles(fileSelector);
for (FileObject file : files) {
// do something
}
source
share