I\'d like to use DirectoryStream with Project Reactor to list all the files in a directory.
My try is:
Path myDir = Paths.get(\"C:\\\\Users\\\\r.dacanal\
Subscribe repeatedly calls iterator(), but DirectoryStream has a check to ensure that the iterator must be null before assigning it's own
@Override
public Iterator iterator() {
if (!isOpen) {
throw new IllegalStateException("Directory stream is closed");
}
synchronized (this) {
if (iterator != null)
throw new IllegalStateException("Iterator already obtained");
iterator = new WindowsDirectoryIterator(firstName);
return iterator;
}
}
Although if you are using Java 8+ there is 0 reason to be using newDirectoryStream(dir)
as you can use list(dir)
to provide an actual Stream
The following should work
Path myDir = Paths.get("C:\\Users\\r.dacanal\\Documents\\Reply\\EDA\\logging-consumer\\input");
Stream directoryStream = Files.list(myDir);
Flux.fromStream(directoryStream).doOnNext(System.out::println).subscribe();