0

maybe the answer to my question is not as straightforward as I'm thinking and also I can't find anything on the internet about it.

So let's say I have this:

String[] line;
BufferedReader data = new BufferedReader(new InputStreamReader(url.openStream()));
CSVReader csvReader = new CSVReaderBuilder(data).withSkipLines(2).build();

...

while((line = csvReader.readNext()) != null){
 # some more code
}

So my question is: is there something like .readPrevious()? Or some function to start reading from the end or "invert" an array if you might.

As I said, it might sound dumb or maybe is because I'm exhausted, but I can't seem to find a straightforward solution.

jgamb
  • 15
  • 5
  • You can store your previous read lines in a list, stack etc. or just in a local variable – Charles Feb 24 '22 at 20:11
  • There is nothing built-in that will return lines in reverse order. If the file is small enough you can read the entire file into memory and process the lines in reverse order. If it's too big to fit into memory, and if there's a sort key in the data that defines the order, you could `sort -r` on that key. If there's no key you'll have to create a reversed version of the file yourself. – Jim Garrison Feb 24 '22 at 20:18

0 Answers0