Reading and skipping blank line from a file...
first I'd like to thank Mike for the help with the last post ;-)
Then here I go with the next problem :-)
Now I know How read the whole content of a text file and store it
into a variable. But what I should do is while reading the file, skip all
the blank line in it. Ex:
This is text
How to skip the blank line between the Text ?
I have just switched from perl to Java so I'm not enought experienced.
Thank for your Help,
Re: Reading and skipping blank line from a file...
> Now I know How read the whole content of a text file and store it
> into a variable. But what I should do is while reading the file, skip all
> the blank line in it. Ex:
> This is text
> Text again.
> How to skip the blank line between the Text ?
> I have just switched from perl to Java so I'm not enought experienced.
It doesn't matter what language you're using, first you have to design the
program. Your design is something like:
Read a line.
If the line isn't blank, write it out (or add it to the block that you will
So I think your question is now: How do I tell if a string is blank?
Do you have the Java documentation? If you don't, you need to download it
from http://java.sun.com/products/jdk/1.2...oad-docs.html. Then if you
look in the documentation for the String class, you'll find a method called
"trim" that removes whitespace from a string. A string is blank if there's
nothing left when you remove the whitespace. How do you tell if there's
nothing left? Well, if the length is zero. So:
if (yourString.trim().length() != 0) then...
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL