wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Word Counter - just count odd lines? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Word Counter - just count odd lines? " Watch "Word Counter - just count odd lines? " New topic
Author

Word Counter - just count odd lines?

Nick Wu
Greenhorn

Joined: Apr 07, 2004
Posts: 1
hello all
I am new to Java and doing a code to count the specific words in a text file and print them with the line number.
The code below is the sample main method which I havenot combined with other classes.
The problem I encountered is that this main method only print the odd lines in the text files. Anyone can show me how to resolve it? Thanks.
Brian Pipa
Ranch Hand

Joined: Sep 29, 2003
Posts: 299
You first problem lies here:

In the if statement itself, you call inFile.readLine() which reads a line but you don't do anything with it so it gets lost. Whenever you read a line, you need to store/use it. Since this sounds like a homework problem, I won't give you the answer but that should get you on the right track.
Brian


My Java Freeware:<br />MACCC - <a href="http://maccc.pipasoft.com" target="_blank" rel="nofollow">http://maccc.pipasoft.com</a><br />Nator - <a href="http://nator.pipasoft.com" target="_blank" rel="nofollow">http://nator.pipasoft.com</a>
 
 
subject: Word Counter - just count odd lines?
 
Similar Threads
travel agent - java writing to file via user input
unable to exit program..
Need a little help...
deleting record
getting no such element exception