I want to stream the lines contained in files but deleting each file once it has been processed.
The current process is like this:
Explanation:
- I create a Stream of Files
- I create a BufferedReader for each one of them
- I flatMap to the lines Stream of the BufferedReader
- I print each line.
Code:
(1) Stream.generate(localFileProvider::getNextFile)
(2) .map(file -> return new BufferedReader(new InputStreamReader(new FileInputStream(file))))
(3) .flatMap(BufferedReader::lines)
(4) .map(System.out::println);
Would it be possible to delete each file once it has been completely read and continue processing the other files in the stream?
Thank you!