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();
}
}
}
原文地址:http://www.cnblogs.com/H2921306656/archive/2016/07/10/5658752.html