java 取出文本文件中的空行
1 import java.io.BufferedInputStream; 2 import java.io.BufferedReader; 3 import java.io.File; 4 import java.io.FileInputStream; 5 import java.io.FileWriter; 6 import java.io.IOException; 7 import java.io.InputStream; 8 import java.io.InputStreamReader; 9 10 public class qukonghang { 11 private static String filename1; 12 private static String filename2; 13 public static void main(String[] args) { 14 filename1="file1"; 15 filename2="file2"; 16 File file=new File(filename1); 17 InputStream is=null; 18 BufferedReader br = null; 19 String tmp; 20 FileWriter writer=null; 21 int i=0; 22 try { 23 is=new BufferedInputStream(new FileInputStream(file)); 24 br = new BufferedReader(new InputStreamReader(is, "utf-8")); 25 writer = new FileWriter(filename2, true); 26 while((tmp=br.readLine())!=null){ 27 if(tmp.equals("")); 28 else{ 29 writer.write(tmp+"\n"); 30 i++; 31 System.out.println(i); 32 } 33 } 34 writer.close(); 35 is.close(); 36 } catch (IOException e) { 37 e.printStackTrace(); 38 } 39 } 40 }