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

[604 byte] By [sameer_13va] at [2007-11-27 10:43:36]
# 1

Does this delimiter "TES 001-" only occur at the start of a line?

BigDaddyLoveHandlesa at 2007-7-28 20:01:22 > top of Java-index,Java Essentials,Java Programming...
# 2

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)

jGardnera at 2007-7-28 20:01:22 > top of Java-index,Java Essentials,Java Programming...
# 3

Thats right, this delimeter just occurs when ever line start's

sameer_13va at 2007-7-28 20:01:22 > top of Java-index,Java Essentials,Java Programming...
# 4

Then reply #2 solves your problem.

BigDaddyLoveHandlesa at 2007-7-28 20:01:22 > top of Java-index,Java Essentials,Java Programming...
# 5

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.

malcolmmca at 2007-7-28 20:01:22 > top of Java-index,Java Essentials,Java Programming...
# 6

Thanks Guys, I got the idea how to move ahead, If any one have any sample will be great.

sameer_13va at 2007-7-28 20:01:22 > top of Java-index,Java Essentials,Java Programming...
# 7

> If any one have any sample will be great.

Post what you have and I'm sure you get some tips.

BigDaddyLoveHandlesa at 2007-7-28 20:01:22 > top of Java-index,Java Essentials,Java Programming...