Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > (newbie) definitive class/regex for stripping empty lines from text files?

Reply
Thread Tools

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

 
 
christek
Guest
Posts: n/a
 
      01-31-2007
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

 
Reply With Quote
 
 
 
 
Gordon Beaton
Guest
Posts: n/a
 
      01-31-2007
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Regexes] Stripping puctuation from a text shabda raaj Python 1 05-23-2008 07:21 AM
Preserve blank lines when add multiple lines of text to a cell Cah Sableng Javascript 0 04-23-2007 04:46 AM
To delete few lines and add few lines at the end of a text file using c program Murali C++ 2 03-09-2006 04:45 PM
Stripping html tags from text Spondishy ASP .Net 4 03-07-2006 03:45 PM
Stripping text in variables Andie ASP General 0 08-19-2003 07:54 PM



Advertisments