String Tokenizer hanging at run-time

//Creating the object array and reading values into it

try{

String fileName = "BOBSDB.txt";

//connect the stream tokeniser to the file

FileInputStream stream = new FileInputStream(fileName);

InputStreamReader iStreamReader = new InputStreamReader(stream);

BufferedReader bufReader = new BufferedReader(iStreamReader);

StreamTokenizer reader = new StreamTokenizer(bufReader);

try{

BookList1729731[] BookList = new BookList1729731[10];

int arrayCounter = 0, readerCounter = 0, isbn = 0, numInStock = 0;

String title = "";

float price = 0;

reader.nextToken();

while(reader.ttype != StreamTokenizer.TT_EOF){

while(reader.ttype != StreamTokenizer.TT_EOL){

switch(readerCounter){

case 0:

isbn = (int)reader.nval;

break;

case 1:

title = reader.sval;

break;

case 2:

numInStock = (int)reader.nval;

break;

case 3:

price = (float)reader.nval;

break;

}

readerCounter ++;

}

BookList[arrayCounter] = new BookList1729731(isbn, title, numInStock, price);

readerCounter = 0;

arrayCounter ++;

}

}

catch(IOException e){

JOptionPane.showMessageDialog(null, "error in file input:" + e);

}

}

catch(IOException e){

JOptionPane.showMessageDialog(null, "error in opening file for input:" + e);

}

The code compiles fine but when I run the program it hangs. If this section of the code is commented out it opens fine so it must be here somewhere.

Stu

[1622 byte] By [jedi Stu] at [2007-9-26 7:34:32]
# 1
You are not reading any tokens after the first token. You have the while loops, but you are not reading any more tokens inside the loops.
ashutosh at 2007-7-1 17:34:19 > top of Java-index,Core,Core APIs...
# 2

Here is a working version, I just tried it on my computer:

String fileName = "data.txt";

FileInputStream stream = new FileInputStream(fileName);

InputStreamReader iStreamReader = new InputStreamReader(stream);

BufferedReader bufReader = new BufferedReader(iStreamReader);

BookList1729731[] BookList = new BookList1729731[10]; //make sure your file does not have more than 10 lines

int arrayCounter = 0;

String line = "";

while ( (line=bufReader.readLine()) != null) {

StringTokenizer st = new StringTokenizer(line, ","); //assuming comma delimited data

int isbn = Integer.parseInt(st.nextToken());

String title = st.nextToken();

int numInStock = Integer.parseInt(st.nextToken());

float price = Float.parseFloat(st.nextToken());

BookList[arrayCounter] = new BookList1729731(isbn, title, numInStock, price);

arrayCounter++;

}

ashutosh at 2007-7-1 17:34:19 > top of Java-index,Core,Core APIs...
# 3
Dude, if there was a better way of saying you're a legend I'd say it. Thanks heaps for this.Stu
jedi Stu at 2007-7-1 17:34:19 > top of Java-index,Core,Core APIs...