• Post Reply Bookmark Topic Watch Topic
  • New Topic

Reading a file  RSS feed

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I read the number of lines in a file using Scanner/FileReader the output is always two more than the real total number.For e.g.,
I am new to java
I have started liking the languge.

The output is 4 instead of 2.Why is that?
 
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Show us how you're reading the file.
 
Ranch Hand
Posts: 384
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
could you please post your code ...

Lucky
 
Ranu Kundu
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe you have some empty lines. Use System.out.println("["+line+"]");

And UseCodeTags the next time you post some code.
 
Lalit Mehra
Ranch Hand
Posts: 384
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
buddy your code is fine ... you better should check whether there are some unwanted empty lines in your "mech.txt" file
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!