Reading and skipping blank line from a file...


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Reading and skipping blank line from a file...

Hybrid View

  1. #1
    Gabriele Guest

    Reading and skipping blank line from a file...


    Hi all,
    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


    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.

    Thank for your Help,
    Gabriele


  2. #2
    Paul Clapham Guest

    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
    output later).

    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...




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center