 <p>You invoke the nextToken() method 3 times. That will get you 3 different tokens</p> <pre><code>int pos = productsTokenizer .nextToken().indexOf("-"); String product = productsTokenizer .nextToken().substring(0, pos+1); String count= productsTokenizer .nextToken().substring(pos, pos+1); </code></pre> <p>Instead you should do something like:</p> <pre><code>String token = productsTokenizer .nextToken(); int pos = token.indexOf("-"); String product = token.substring(...); String count= token.substring(...); </code></pre> <p>I'll let you figure out the proper indexes for the substring() method.</p> <p>Also instead of using a do/while structure it is better to just use a while loop:</p> <pre><code>while(productsTokenizer .hasMoreTokens()) { // add your code here } </code></pre> <p>That is don't assume there is a token.</p>