使用新File API的目录中的文件列表 [英] List of files in directory with new File API
本文介绍了使用新File API的目录中的文件列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在旧的API中,您可以使用方法 File.list()
和 File.listFiles()
。如何使用新API获得类似的东西? 这里你可以看到如何浏览文件树,但我想要的不是比第一级更深入,如 File.list()
确实。
In the old API you could get the files in a directory with the methods File.list()
and File.listFiles()
. How do you get something similar using the new API? Here you can see how to walk through a file tree but what I want is not to go deeper than the first level like File.list()
does.
要有一个小应用程序,你可以写一个程序代码来打印由 java.nio.file.Path
对象路径
按字母顺序排列到标准输出的目录的文件名。
To have a little application you could write as answer the code for a program which prints the file names of a directory given by a java.nio.file.Path
object path
alphabetically ordered to the standard output.
推荐答案
这个怎么样?
Files.list(Paths.get("somedir")).sorted().forEach(System.out::println);
这篇关于使用新File API的目录中的文件列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文