I am trying to find the way to read from the file the first 10 information's through the array (not arraylist)ProdName and the quantity." plus that I stack in the in.readLine(); propably is not compatible with the StringTokenizer.
Now the other problem is that I need the quantity to be an integer instead of string.

Please read this topic to learn how to post code correctly and other useful tips for newcomers. Edit your post to fix it, if possible.

Explain better what you want help with. Which of the parts you described have you stuck? Reading the file, storing the desired data in the array, etc.? Are you getting errors or unsatisfactory results? If so, copy the error from exactly as it appears at your end and paste it into your post. If the results are not as expected, copy a sample run and post that with a description of what needs to change.

The following give me the error:
Type mismatch: cannot convert from String to StringTokenizer
The constructor StringTokenizer(StringTokenizer) is undefined
Type mismatch: cannot convert from String to StringTokenizer

at Main.main(Main.java:14)

December 8th, 2013, 04:37 AM

andbin

Re: Array & file

Quote:

Originally Posted by mikerousse

The following give me the error:
Type mismatch: cannot convert from String to StringTokenizer
The constructor StringTokenizer(StringTokenizer) is undefined
Type mismatch: cannot convert from String to StringTokenizer

Even I take out the prodname & quantity the program still works which mean is useless.

--- Update ---

How can I make them to work?

December 8th, 2013, 05:57 AM

andbin

Re: Array & file

Quote:

Originally Posted by mikerousse

Even I take out the prodname & quantity the program still works which mean is useless.

How can I make them to work?

Lines you have commented (declaration and assignment of ProdName/quantity) are not bad or unuseful. They serve as the base for the rest you still need to do.

You have asked for other things:

1) You want the quantity as an int. I have told you that there is parseInt, which is a static method of Integer class. So invoke Integer.parseInt(quantity) to obtain an int you should assign to a variable. Note that the parsing may fail with a NumberFormatException.

2) You want an array. Do you known, in advance, how many entities you have in the file? An array must be instantiated with a well known size.

3) You need a class to "model" the entity composed by product name plus quantity. Do you know how to define a class with some instance variables and appropriate accessor (setter/getter) methods?