List<File> fileListToProcess = Arrays.stream(allFolderPath)
.filter(myFile -> myFile.getName().matches("archive_"))
.collect(Collectors.toList());
我正在过滤以"archive_"开头的文件,以使用正则表达式和流进行处理。这行不通。我在这里做错了什么?
您可以使用String's
startsWith
方法:
List<File> fileListToProcess = Arrays.stream(allFolderPath)
.filter(myFile -> myFile.getName().startsWith("archive_"))
.collect(Collectors.toList());
或者您可以使用以下正则表达式来检查字符串是否以archive_
开头:
^(archive_(.*
喜欢:
List<File> fileListToProcess = Arrays.stream(allFolderPath)
.filter(myFile -> myFile.getName().matches("^(archive_).*"))
.collect(Collectors.toList());