Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Java regex: remove blank lines

807605Aug 8 2007 — edited Aug 8 2007
I'm tring to remove all blank lines in a txt file. What I did was:
Pattern p = Pattern.compile("^\\s*$", Pattern.MULTILINE);
Matcher m = p.matcher(myFile);
System.out.println(m.replaceAll(""));
However, this did not remove the blank lines. Any ideas?

Thanks.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 5 2007
Added on Aug 8 2007
5 comments
4,142 views