(newbie) definitive class/regex for stripping empty lines from text files?

Discussion in 'Java' started by christek, Jan 31, 2007.

  1. christek

    christek Guest

    Hello all,
    This would seem to be a common task but I can't seem to find an answer
    on the web.
    Is there a definitive/well tested class/library that can strip blank
    lines and lines with nothing but spaces from a text file using
    FileInputStream?
    Regards,
    Chris
     
    christek, Jan 31, 2007
    #1
    1. Advertising

  2. On 31 Jan 2007 02:10:45 -0800, christek wrote:
    > This would seem to be a common task but I can't seem to find an
    > answer on the web. Is there a definitive/well tested class/library
    > that can strip blank lines and lines with nothing but spaces from a
    > text file using FileInputStream?


    How difficult can it be to add a one-line conditional to the standard
    idiom...

    BufferedReader br = new BufferedReader(...);
    String line;

    while ((line = br.readLine()) != null) {
    if (line.trim().length() != 0) {
    // whatever
    }
    }

    br.close();

    Note too that you should be using a Reader to handle text files, not
    an InputStream.

    /gordon

    --
    [ don't email me support questions or followups ]
    g o r d o n + n e w s @ b a l d e r 1 3 . s e
     
    Gordon Beaton, Jan 31, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Michael Vilain

    regex for stripping HTML

    Michael Vilain, Oct 28, 2003, in forum: Perl
    Replies:
    4
    Views:
    681
    Anno Siegel
    Oct 30, 2003
  2. Murali
    Replies:
    2
    Views:
    613
    Jerry Coffin
    Mar 9, 2006
  3. Michael Vilain

    regex for stripping HTML

    Michael Vilain, Oct 28, 2003, in forum: Perl Misc
    Replies:
    8
    Views:
    124
    Alan J. Flavell
    Oct 30, 2003
  4. tor
    Replies:
    6
    Views:
    1,650
    Jeff 'japhy' Pinyan
    Dec 10, 2003
  5. Cah Sableng
    Replies:
    0
    Views:
    264
    Cah Sableng
    Apr 23, 2007
Loading...

Share This Page