I have a file like -
--------------
abc
efg
hig
---------------
xyz
pqr
---------------
fdg
gege
ger
ger
---------------
Whats the best way to write java code which parses this file and creates separate List for each of the block of text between dashes. For example -
List<String> List1 = {abc, efg, hig}
List<String> List2 = {xyz, pqr}
List<String> List3 = {fdg, gege, ger, ger}
You can use
java.nio.file.Files.lines(Path path)to read a file and read each line usingStream<String>to represent single line of an input file. Here is some short example:Output