public class SafeFiles
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
canonicalFileName(java.nio.file.Path path)
Path.getFileName() includes a slash sometimes for some reason. |
static java.util.stream.Stream<java.nio.file.Path> |
noLeakFileList(java.nio.file.Path dir)
A version of
Files.list(Path) that won't leak resources. |
public static java.util.stream.Stream<java.nio.file.Path> noLeakFileList(java.nio.file.Path dir) throws java.io.IOException
Files.list(Path)
that won't leak resources.
Instead, it immediately consumes the entire listing into a List
and
calls Collection.stream()
.
dir
- the directory to listjava.io.IOException
- if an I/O error occurspublic static java.lang.String canonicalFileName(java.nio.file.Path path)
Path.getFileName()
includes a slash sometimes for some reason.
This will get rid of it.path
- the path to get the file name for