I am trying to read product information from some text files. In my text file I have products and their information.
This is my file:
Product1: ID: 1232 Name: ABC35 InStock: Yes
As you see, some products have blank lines in their product information, and I was wondering if there is any good way to determine if the line is blank, then read the next line.
How can I accomplish that? If the reading line is blank, then read the next line.
Thanks in advance for any help.
I think I may be misunderstanding. Assuming you have a
BufferedReader, your main processing loop would be:Update: Re your comment:
The above is how I would structure my processing loop, but if you prefer, you can simply use a function that returns the next non-blank line:
That returns
nullat EOF likereadLinedoes, or returns the next line that doesn’t consist entirely of whitespace. Note that it doesn’t strip whitespace from the line (my processing loop above does, because usually when I’m doing this, I want the whitespace trimmed off lines even if they’re not blank).