第五題
import java.io.*; public class IOmain { public static void main(String[] args) { // 定義源文件路徑和目標(biāo)文件路徑 String srcPath = "d:/test1.txt"; String destPath = "d:/test2.txt"; // 創(chuàng)建輸入流和輸出流 BufferedReader reader = null; BufferedWriter writer = null; try { reader = new BufferedReader(new FileReader(srcPath)); writer = new BufferedWriter(new FileWriter(destPath)); // 一次讀取一行數(shù)據(jù) String line; while ((line = reader.readLine()) != null) { // 將數(shù)字替換為空字符串 line = line.replaceAll("\\d", ""); // 寫入目標(biāo)文件 writer.write(line); // 換行 writer.newLine(); } } catch (IOException e) { e.printStackTrace(); } finally { // 關(guān)閉輸入流和輸出流 if (reader != null) { try { reader.close(); } catch (IOException e) { e.printStackTrace(); } } if (writer != null) { try { writer.close(); } catch (IOException e) { e.printStackTrace(); } } } } }