How do I find the last modified file in a directory in java?
Let's assume that the variable thePath contains the directory we want to search, the following snippet returns the last modified file inside it:
Files.walk(thePath)
.sorted((f1, f2) -> -(int)(f1.toFile().lastModified() - f2.toFile().lastModified()))
.skip(1)
.findFirst()
What it does is: