标签:catch path eem file close edr put exception null
import java.io.*; public class RemoveEmp3{ public static void readwrite(String filePath)throws IOException{ FileInputStream finput = new FileInputStream(filePath); InputStreamReader isr = new InputStreamReader(finput); BufferedReader br = new BufferedReader(isr); File file = new File("new.java"); if(!file.exists()){ file.createNewFile(); } FileOutputStream fos = new FileOutputStream(file); OutputStreamWriter osw = new OutputStreamWriter(fos); for(String line = br.readLine();line!=null;line = br.readLine()){ if(line.matches("^[\\s&&[^\\n]]*$")){//空行的转义字符 ; } else{ osw.write(line+"\n"); System.out.println(line); } } br.close(); osw.close(); } public static void main(String[] args){ String str1 = "E:/A课程学习资料/软件构造 刘丹/软件构造/代码去空行器(自己写的)/RemoveEmp2.java"; try{ readwrite(str1); }catch(IOException e){ ; } } }
空行的转义字符:^[\\s&&[^\\n]]*$
标签:catch path eem file close edr put exception null
原文地址:https://www.cnblogs.com/jmdd/p/12113220.html