How to create Objects from reading the .Txt file

PolicynoCompany_NameChildPolicy

-

5197AIRCHANNEL LTDSHANKA15513A

5197AIRCHANNEL LTDSHANKA27760B

5197AIRCHANNEL LTDSHANKP17946A

5201GLENMORE ENGINEERING RICHP97946X

5201GLENMORE ENGINEERINGRICHP97946M

5201GLENMORE ENGINEERING RICHP97946D

I am getting the dat(flat) file , this file contains records to health policy.

Each policy contains sub policies called child policy.So need to read the dat file and create objects called Policy which contains sub class called child policies..

Policy

{

String policy_name;

int Polic_no;

ChildPolicy childpo;

// some getters and setters

}

ChildPolicy

{

//some getter and setters

}

Any help .....

[971 byte] By [avina_SMPPa] at [2007-11-27 10:30:06]
# 1

Do you have a specific question?

prometheuzza at 2007-7-28 18:01:16 > top of Java-index,Java Essentials,Java Programming...
# 2

Help how to create objects from reading the .txt file..

avina_SMPPa at 2007-7-28 18:01:16 > top of Java-index,Java Essentials,Java Programming...
# 3

create a constructor that accepts String objects... create the object by calling that constructor and passing the String that u read from the file.... That's it... simple though...

@@CKM@@a at 2007-7-28 18:01:16 > top of Java-index,Java Essentials,Java Programming...
# 4

> Help how to create objects from reading the .txt

> file..

Here's explained how to go about reading bytes/text from a file:

http://java.sun.com/docs/books/tutorial/essential/io/

And here's a detailed tutorial how to create your own custom classes:

http://java.sun.com/docs/books/tutorial/java/javaOO/index.html

Good luck.

prometheuzza at 2007-7-28 18:01:16 > top of Java-index,Java Essentials,Java Programming...
# 5

A sample example wil help

avina_SMPPa at 2007-7-28 18:01:16 > top of Java-index,Java Essentials,Java Programming...
# 6

> A sample example wil help

Examples are in the links I posted.

prometheuzza at 2007-7-28 18:01:16 > top of Java-index,Java Essentials,Java Programming...
# 7

It looks like you have three fields, you want to find the first space, the last space (indexOf, lastIndexOf) and chop up the String with substring.

Then use Integer.parseInteger() to translate the policy number to a numeric value.

You need to think about what happens if the line is invalid. For example what do you do if there aren't two spaces, or the first field isn't a number?

malcolmmca at 2007-7-28 18:01:16 > top of Java-index,Java Essentials,Java Programming...