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

C

christek

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
 
G

Gordon Beaton

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top