Java functional programming (11): traversing directories

Lists the files in the directory

Using the list () method of the file class, you can easily list the file names of all files in the directory. If you want to get a file, not just the file name, you can use its listfiles () method. This is very simple. The difficulty is how to deal with the returned list. Instead of using traditional verbose external iterators, we use elegant functional expressions to actually traverse the list. Here we also need to use the new closeablestream interface of JDK and some related high-order functions.

The following code can list the names of all files in the current directory.

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
分享
二维码
< <上一篇
下一篇>>