[英]List all files of a particular type inside a directory on a remote machine in JAVA
[英]Java code to list in all files from a directory with a particular word in filename
我有一個包含大量文件的目錄,我需要列出該目錄中的所有文件,名稱上有一個特定的詞,例如 India 或其他。 另外如何獲取該文件的路徑?
這樣的事情應該工作:
try (Stream<Path> paths = Files.walk(Paths.get("/home/you/Desktop"))) {
paths
.filter(Files::isRegularFile)
// You can also use Apache StringUtils.containsIgnoreCase()
.filter(path -> path.getFileName().toString().toLowerCase().contains(word.toLowerCase()))
.forEach(System.out::println);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.