Java Files.walk examples

The Files.walk API is available since Java 8; it helps to walk a file tree at a given starting path. Topics Files.walk() method signature List all files List all folders or directories Find files by file extension Find files by filename Find files by file size Update all files last modified date 1. Files.walk() method …

Read more

How to delete directory in Java

If we use the NIO Files.delete to delete a non-empty directory in Java, it throws DirectoryNotEmptyException; for legacy IO File.delete to delete a non-empty directory, it returns a false. The standard solution is to loop the directory recursively, and delete all its children’s contents first (sub-files or sub-directories), and delete the parent later. This example …

Read more