D
D
DDwrt1002020-01-17 12:59:34
Java
DDwrt100, 2020-01-17 12:59:34

What is wrong in the Stream API expression?

Good afternoon, please tell me what is wrong in the Stream api statement.
I want to get a list of files from a certain directory with a certain permission, for example jpg.

List<File> pathFiles = Files.walk(startURI).filter(Files::isRegularFile)
          .filter(x-> x.endsWith(".jpg"))
          .map(Path::toFile).collect(Collectors.toList());

If I use the following expression: Then the sheet is empty. Without this expression, I get just a List of all files.
.filter(x-> x.endsWith(".jpg"))

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
roswell, 2020-01-17
@DDwrt100

.filter(x -> x.toString().endsWith(".jpg"))

R
Roman, 2020-01-17
@Terran37

Try using toLowerCase() before looking for extension by extension.
Something like this .filter(x-> x.toLowerCase().endsWith(".jpg"))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question