reading and parsing fixed length text file

  • Thread starter Julian McMaster
  • Start date
J

Julian McMaster

I need to use Java to read, parse and process a fixed length text file. The
data fields are fixed, such that field1 starts at 0 and is N bytes long,
field2 starts at 20 and is N bytes long, etc. etc. Some fields are long and
will span multiple rows. There could even be breaks in the file where a few
lines are skipped.

What's the best way to approach this with Java? Is there an I/O class that
works best for this, or better yet, is specifically designed to work with
fixed length text files?

Thanks in advance for any advice.

Julian
 
R

Roedy Green

What's the best way to approach this with Java? Is there an I/O class that
works best for this, or better yet, is specifically designed to work with
fixed length text files?

Most easily you can forget the fixed lengthness of it and read it a
line at a time then split the line into pieces with substring.

See http://mindprod.com/applets/fileio.html

tell it you have character data encoded. I trust you know the
encoding.

You could also read it a field at a time using a BufferedReader.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top