• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to skip reading empty lines in text file

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All
I am a novice for Java, just trying out to master the skills.
I am doing a self assignment in which I read data from a csv file or text file and print the no of lines
Now my text file has empty lines, I want to skip reading the empty line. The code which I have written takes all the lines and print the no of lines, I am posting my code here, please check it and guide me on how to avoid reading empty lines and go to next line.
My present code is

Please guide and advice me on how to skip the empty lines, while counting
 
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to execute lines 11 - 13 only if the line is not empty. So you need some construct that executes some code only if a condition is met. Do you know if such a construct exists in Java ?
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch.

In pseudo code
1) Remove all white spaces. (Empty quotes are called white spaces.e.g. " ") Check out the String API to find existing methods to trim (hint) these white spaces
2) Then check the length (hint) of the string. If it is zero, then the line is empty.
3) If empty, skip, else process (hint hint)
 
reply
    Bookmark Topic Watch Topic
  • New Topic