I have create the following program and I am little stuck here. Here is the code:
class ProductNameQuan{
public static void main(String[] args)
{
String fileName = "stockhouse.txt";
StringTokenizer line;
String ProdName;
String quantity;
try {
BufferedReader in = new BufferedReader(new FileReader(fileName));
line = in.readLine();
while (line != null) {
ProdName = line.nextToken();
quantity = line.nextToken();
System.out.println(line);
line = in.readLine();
}
in.close();
} catch (IOException iox)
{
System.out.println("Problem reading " + fileName);
}
}
}
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.
The file includes something like that: Ball 32 tennis 322 fireball 54 .. . . . . Any ideas?
I would place this in a helper function, maybe called
parseString