Find files in a folder using Java

前端 未结 12 1945
日久生厌
日久生厌 2020-11-28 08:15

What I need to do if Search a folder say C:\\example

I then need to go through each file and check to see if it matches a few start characters so if fil

12条回答
  •  忘掉有多难
    2020-11-28 08:36

    I know, this is an old question. But just for the sake of completeness, the lambda version.

    File dir = new File(directory);
    File[] files = dir.listFiles((dir1, name) -> name.startsWith("temp") && name.endsWith(".txt"));
    

提交回复
热议问题