基本上,我正在做一个程序,以保存在记事本中的用户笔记是.txt格式和用户有他的文件夹名称与他的用户名,他也可以创建一个子目录中。因此,我想,每当他保存一个文件,有一个检查应用,例如,如果他保存与名称note1在主目录,那么应该没有其他文件命名为注意1的子目录太。
给定
String filename ;
Path directory ;
你可以做。
Optional<Path> matchingFileName = Files.walk(directory)
.filter(path -> path.endsWith(Paths.get(filename))
.findAny();
if (matchingFileName.isPresent()) {
// there's a matching filename in a subdirectory
}