java实现文本文件删除空行的示例分享
程序员文章站
2022-04-05 14:39:02
...
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(); } } }
更多java实现文本文件删除空行的示例分享相关文章请关注PHP中文网!
更多java实现文本文件删除空行的示例分享相关文章请关注PHP中文网!
上一篇: seo和php哪个值得学