Hi friends,
I’m stuck in this problem with flows:
I need to have a flow from a file, but keeping it open (as a “tail -f” on the file).
I attach more info just in this same thread to keep it “readable”… THANKS A LOT
earroyoron
02/23/2020, 9:22 PM
Hi friends,
I’m stuck in this problem with flows:
I need to have a flow from a file, but keeping it open (as a “tail -f” on the file).
I started with something as:
Copy code
val stream: Flow<String> = File(arguments.filename).readLines().asFlow()
gets all content and closes the stream. but and I though it could be easy to “iterate” to the next version that do not close the stream over the file.
BUT I CANNOT FIND HOW TO KEEP THE FLOW “LIVE” ??
Some idea?
PD: I tried to use a Timer to run periodically the “collector” but in this case the file is always read “from the beggining”… 😞
s
satyan
02/24/2020, 7:22 AM
Just Google "Java file watcher" you can register a watch service which receives updates when a directory changes and then filter to a specific file.
Wrapping it as a Flow should be straight forward