Reading Fixed Length Files

I have 4 files that i need to read that are in a fixed length format. I have one property file that defines the lengths of each field. For example:

location.fieldName = CompanyNum, LocationNum, MailingStreet1, MailingCity, MailingState, MailingCountry, MailingZip

location.fieldLength = 5,4,35,15,2,2,5

Given that i am new, i don't know how to parse each line i read based on these values. Can someone assist me with an example or information?

[469 byte] By [Nexeha] at [2007-11-27 11:57:32]
# 1

I would call that a fixed-width file, not a fixed-length file.

Read the file, line-by-line (say, using BufferedReader).

Given a string holding the content of a given line, partition it using substring.

ParvatiDevia at 2007-7-29 19:14:28 > top of Java-index,Java Essentials,New To Java...
# 2

What do you need help with, reading the properties file, or parsing the fixed length file?

hunter9000a at 2007-7-29 19:14:28 > top of Java-index,Java Essentials,New To Java...
# 3

I can read the file with no problem and i can read the properties file with no problem. Now i need to parse the line from the file with the information i got from the properties.

Someone suggested substring would be the way to do this...

i can try this, it looks like it wants the starting and ending index.. I'm assuming there is no class set to read a set width?

Nexeha at 2007-7-29 19:14:28 > top of Java-index,Java Essentials,New To Java...
# 4

Use the String.substring(int startIndex, int endIndex) method:

http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html#substring(int,%20int)

The first string starts at 0, and ends at the width of the first record.

The second starts after the width of the first record, and ends at the width of the first record + the width of the second.

Rinse, repeat.

hunter9000a at 2007-7-29 19:14:28 > top of Java-index,Java Essentials,New To Java...