I have a method that iterates over the lines of a file. Currently, he is completely dancing, opening the file and closing it.
Now I want to change the method so that I can pass an instance of some interface, it is possible Iterator<String>that I can either read from a file or just get lines from List<String>if I want to provide input directly.
Is there any convenient way to do this? Writing your own method of getting Iterator<String>from Fileseems like it would be very difficult to get the right results.
I think the closest way I can think of is to use Guava Files.readLines () , but this is not an iterator, so it has problems with very large files.
source
share