Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2005

Tip: Looking for answers? Try searching our database.

reading and parsing fixed length text file

Thread view: 
Julian McMaster - 08 Nov 2005 01:34 GMT
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
Roedy Green - 08 Nov 2005 02:45 GMT
On Mon, 7 Nov 2005 20:34:55 -0500, "Julian McMaster"
<fideliteus@yahoo.com> wrote, quoted or indirectly quoted someone who
said :

>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.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.