指定したディレクトリ内のすべてのファイルと、そのディレクトリ内のサブディレクトリを一覧表示したいと考えています。ディレクトリをリストする必要はありません。
私の現在のコードは以下です。指定したディレクトリ内のファイルとディレクトリのみを一覧表示するため、正しく機能しません。
どうすればこれを修正できますか?
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());
}