I've been stuck on this for a while and I've finally decided to plead for help.
So I have a small text file and the user wants to switch 2 lines from it, the user enters the indexes of the 2 lines and I have to switch em.
So far my ideas have been to either use replaceALL with 2 regexes
, but A: That probably won't switch them but just end up replacing one with the other, leaving me with a duplicate and B: I have no idea how to locate the nth line using regex;
or use - Files.readAllLines(Paths.get(name)).get(index); to get the two lines but then I'm still struggling with the actual switching process.
You can use
Files.readAllLinesto get all lines as a list
If you need to be able to work with large files you could