传入pattern
和format
,因为他们都较低套管,我怎么可以改变的代码下面的代码片段,以便startsWith
和endsWith
回报true
如果模式和格式匹配不区分大小写?不区分大小写路径startsWIth的endsWith
try (Stream<Path> paths = Files.find(cobDir, 1,
(path, attrs) -> attrs.isRegularFile()
&& path.getFileName().startsWith(pattern)
&& path.toString().endsWith(format))) {
matchingFile = paths.findFirst();
} catch (IOException e) {
logger.error("Problem with getting files to process {}", e.getMessage());
}
是否有这样做比下面的漂亮方式:
try (Stream<Path> paths = Files.find(cobDir, 1,
(path, attrs) -> attrs.isRegularFile()
&& path.getFileName().toString().toLowerCase().startsWith(pattern)
&& path.toString().toLowerCase().endsWith(format))) {
matchingFile = paths.findFirst();
} catch (IOException e) {
logger.error("Problem with getting files to process {}", e.getMessage());
}
'toUpperCase()'或'toLowerCase()'路径的字符串和'格式'。 –
[查看本问答](https://stackoverflow.com/q/19154117/335858)剧透:这不太好。 – dasblinkenlight