Delete the first element of stream in Java 8

I have used java Files in NiO library The walk () method generates a stream in Java 8 The problem is that the method contains the root path by default, but I don't want this element I have solved this problem in this example. The code uses the filter () method:

public void listFiles(String directoryPath) {
    try {
        Path root = Paths.get(directoryPath);
        Files.walk(root,1)
            .filter(x -> !x.equals(root))
            .forEach(System.out::println);
    } catch (IOException ex) {
        System.err.println("Error reading file: " + directoryPath);
    }
}

My question is if there is a more elegant way to delete the first element of the stream, such as using an index in the stream, or using the tail () method as another functional language

Solution

How to put it Where is skip (1)?

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>