Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Tokenize a string and pass to constructor

Status
Not open for further replies.

og1975ze

Technical User
Jan 22, 2004
5
0
0
US
Can anyone tell me how to read a file (entered as a command line arg.)using the string tokenizer and pass thoses values that were read to a constructor?? Please see my example code:

FileReader theFile;
BufferedReader fileIn = null;
String Currenttoken;
Mortgage m;
\\ I have a clas called Mortgage i need to use

public static void statFile( String fileName )
{
try
{
theFile = new FileReader( fileName );
fileIn = new BufferedReader( theFile );

StringTokenizer st = new StringTokenizer(fileIn);
while (st.hasMoreTokens())
{
m = new Mortgage(theFile);
}


 
You will need to specify the marker that you are going to use to seperate the tokens. ie:

StringTokenizer st = new StringTokenizer(fileIn, ",");

which will split up the file by "," like a comma seperated file.

Hope this helps
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top