This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Program not correctly reading from a text file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Program not correctly reading from a text file" Watch "Program not correctly reading from a text file" New topic
Author

Program not correctly reading from a text file

Gulshan Singh
Ranch Hand

Joined: Apr 22, 2009
Posts: 41
The following code is part of my Flash card program where the user can have two text files, one called questions and the other called answers, and then the program will display the questions and the user can see if he can get the right answer.

This is just the loading of the cards, not the whole program. The problem is not every line in the text file is being loaded. Try it yourself using two text files with the same number of lines, and if the text file was something like,
word1
word2
word3
word4

The ArrayList qlines would be something like
word1
word2
word4
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

Gulshan Singh wrote:



For each round in the loop, you are reading from the buffques twice - once in the while condition, and once in the qlines.add() line. Take the second one out and store tempstr into qlines.


Steve
 
Have you checked out Aspose?
 
subject: Program not correctly reading from a text file
 
It's not a secret anymore!