使用java编写一个删除空行的小程序,要考虑TAB符和ENTER换行等所有情况,请大虾贴代码。

解决方案 »

  1.   

    这是有关正则表达式和java io的,请大虾帮忙啊!
      

  2.   

    import java.io.File;
    import java.io.FileInputStream;
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;import org.junit.After;
    import org.junit.Before;
    import org.junit.Test;public class NTest {    private StringBuilder content = new StringBuilder();    private Pattern pattern = Pattern.compile("(\r\n)*", Pattern.DOTALL);    @Before
        public void setUp() throws Exception {
            FileInputStream fis= null;
            try {
                fis = new FileInputStream(new File("c:/test.txt"));
                byte[] b = new byte[1024];
                int len = -1;
                while ((len = fis.read(b)) != -1) {
                    content.append(new String(b, 0, len));
                }
            } finally {
                if(null != fis)
                    fis.close();
            }
        }    @After
        public void tearDown() throws Exception {
            content = null;
        }    @Test
        public void Ntest() {
            Matcher matcher = pattern.matcher(content);
            int g = matcher.groupCount();
            System.out.println("groupCount="+g);
            while(matcher.find()){
                System.out.println("finded it");
                for (int i = 0; i < g ;i++){
                   System.out.println(matcher.group(i));
                }
                break;
            }
        }
    }
    这个要怎么修改才能完成上面的功能啊?
      

  3.   

     System.out.println(content.toString().replaceAll("\\s",""));