Reading flat file with mutiline records
Hi All,
I am looking for the way to read the file with contains records in multi lines, only way to distinguish between records is start string
"TES 001-" is my case
Sample record is
NameofFile=sample.txt001
TES 001-00017578442P1060054J7994630106518W6E999350975147 65& 0000a
TES 00110U$U$U$0000a
TES 00124000-6000- 0000a
TES 0013RTRAN41832900014RTRAD4251040000a
TES 001-00017578442TES1060054J7999910999318424250975147 65& 0000b
TES 00110U$U$U$0000b
TES 00124000-600- 0000b
Can any one suggest how can I achieve this
If you are reading the file line by line, once you have a line as a String, just use
the startsWith method
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html#startsWith(java.lang.String)
You could write this code a number of ways, it depends mostly on how complex things are likely to get.
I'd probably create a class for the record data, which would probably have a constructor which took the first line, and some kind of processLine method to interpret further lines.
Then you can run through the file with a currentRecord reference variable (initially null). When you find an "-" then you place create a new record object, otherwise call the processLine on the existing one. Add each new record to a List.