java

关注公众号 jb51net

关闭
首页 > 软件编程 > java > java 取出文本文件中空行

java 取出文本文件中空行的实例代码

作者:

这篇文章介绍了java 取出文本文件中空行的实例代码,有需要的朋友可以参考一下

复制代码 代码如下:

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class qukonghang {
    private static String filename1;
    private static String filename2;
    public static void main(String[] args) {
        filename1="file1";
        filename2="file2";
        File file=new File(filename1);
        InputStream is=null;
        BufferedReader br = null;
        String tmp;
        FileWriter writer=null;
        int i=0;
        try {
            is=new BufferedInputStream(new FileInputStream(file));
            br = new BufferedReader(new InputStreamReader(is, "utf-8"));
            writer = new FileWriter(filename2, true);
            while((tmp=br.readLine())!=null){
                if(tmp.equals(""));
                else{
                    writer.write(tmp+"\n");
                    i++;
                    System.out.println(i);
                }
            }
            writer.close();
            is.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

您可能感兴趣的文章:
阅读全文