Parsing a text file with a fixed format in Java
- by EugeneP
Suppose I know a text file format,
say, each line contains 4 fields like this:
firstword secondword thirdword fourthword
firstword2 secondword2 thirdword2 fourthword2
...
and I need to read it fully into memory
I can use this approach:
open a text file
while not EOF
read line by line
split each line by a space
create a new object with four fields extracted from each line
add this object to a Set
Ok, but is there anything better, a special 3-rd party Java library?
So that we could define the structure of each text line beforehand and parse the file with some function
thirdpartylib.setInputTextFileFormat("format.xml");
thirdpartylib.parse(Set, "pathToFile")
?