我想列出指定目录中的所有文件以及该目录中的子目录。没有目录应列出。
我当前的代码如下。它仅列出指定目录中的文件和目录,因此无法正常工作。
我怎样才能解决这个问题?
final List<Path> files = new ArrayList<>();
Path path = Paths.get("C:\\Users\\Danny\\Documents\\workspace\\Test\\bin\\SomeFiles");
try
{
DirectoryStream<Path> stream;
stream = Files.newDirectoryStream(path);
for (Path entry : stream)
{
files.add(entry);
}
stream.close();
}
catch (IOException e)
{
e.printStackTrace();
}
for (Path entry: files)
{
System.out.println(entry.toString());
}
万千封印
慕田峪7331174
繁星点点滴滴
相关分类