About Question enthuware.ocpjp.v21.2.4054 :

All the posts and topics that contain only an error report will be moved here after the error is corrected. This is to ensure that when users view a question in ETS Viewer, the "Discuss" button will not indicate the presence of a discussion that adds no value to the question.

Moderators: Site Manager, fjwalraven

Post Reply
user_m1k0
Posts: 3
Joined: Sat Jan 04, 2025 6:45 am
Contact:

About Question enthuware.ocpjp.v21.2.4054 :

Post by user_m1k0 »

I am not sure the answer

Code: Select all

09:32:55 m1k0@localhost katalog → tree /tmp/temp
/tmp/temp
├── documents
│   ├── files.txt
│   └── pdfs
│       └── new.pdf
├── face.jpg
└── surnames.txt

3 directories, 4 files
09:36:06 m1k0@localhost katalog → cat /home/m1k0/Projekty/piaskownica/tomee1/sandbox/sandbox/src/main/java/enthuware/ocpjp/v21_2_4054/TestClass.java
package enthuware.ocpjp.v21_2_4054;

import java.io.IOException;
import java.nio.file.FileVisitOption;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.stream.Stream;

public class TestClass {
    public static void main(String[] args) {
        try (Stream<Path> sp = Files.walk(
//                Path.of("c:\\temp"),
                Path.of("/tmp/temp"),
                2, FileVisitOption.FOLLOW_LINKS)) {
            sp
                    .filter(p -> p.getName(p.getNameCount() - 1).toString().contains(".txt"))
                    .sorted()
                    .forEach(System.out::println);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
09:36:30 m1k0@localhost katalog → java /home/m1k0/Projekty/piaskownica/tomee1/sandbox/sandbox/src/main/java/enthuware/ocpjp/v21_2_4054/TestClass.java
/tmp/temp/documents/files.txt
/tmp/temp/surnames.txt

admin
Site Admin
Posts: 10384
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v21.2.4054 :

Post by admin »

You are right. The answer is indeed illogical but after investigating I found out that the code snippet was actually supposed to be .contains("n") instead .contains(".txt"). The options and the explanations are written accordingly. Should be updated.

thank you for your feedback!

Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests