第五题
import java.io.*; public class IOmain { public static void main(String[] args) { // 定义源文件路径和目标文件路径 String srcPath = "d:/test1.txt"; String destPath = "d:/test2.txt"; // 创建输入流和输出流 BufferedReader reader = null; BufferedWriter writer = null; try { reader = new BufferedReader(new FileReader(srcPath)); writer = new BufferedWriter(new FileWriter(destPath)); // 一次读取一行数据 String line; while ((line = reader.readLine()) != null) { // 将数字替换为空字符串 line = line.replaceAll("\\d", ""); // 写入目标文件 writer.write(line); // 换行 writer.newLine(); } } catch (IOException e) { e.printStackTrace(); } finally { // 关闭输入流和输出流 if (reader != null) { try { reader.close(); } catch (IOException e) { e.printStackTrace(); } } if (writer != null) { try { writer.close(); } catch (IOException e) { e.printStackTrace(); } } } } }

