package com.hsoedu.file.writer; import java.io.*; public class BufferedCopy_ { public static void main(String[] args) { //不能读取二进制文件 String srcFilePath = "e:\\a.txt"; String deskFilePath = "e:\\a1.txt"; BufferedReader br = null; BufferedWriter bw = null; String line; try { br = new BufferedReader(new FileReader(srcFilePath)); bw = new BufferedWriter(new FileWriter(deskFilePath)); while ((line = br.readLine()) != null) { //每读一行,就写入 bw.write(line); //插入一个换行 bw.newLine(); } System.out.println("拷贝完毕"); } catch (IOException e) { e.printStackTrace(); } finally { if (br != null) { try { br.close(); } catch (IOException e) { e.printStackTrace(); } if (bw != null) { try { bw.close(); } catch (IOException e) { e.printStackTrace(); } finally { } } } } } }
包装流文件拷贝
最新推荐文章于 2024-05-08 15:24:52 发布