BufferedWriter(废稿)

复制代码
public static void main(String[] args) {
    /*
    注意:
    1. BufferedReader 和 BufferedWriter 是按照字符操作的
    2. 不要去操作 二进制文件 【声音、视频、doc、pdf 等】
     */

    String srcFilePath = "F:/a.txt";  // 原文件的路径
    String destFilePath = "F:/aaa.txt";  // 目标位置的路径

    BufferedReader br = null;
    BufferedWriter bw = null;
    String line ;

    try {
        br = new BufferedReader(new FileReader(srcFilePath));
        bw = new BufferedWriter(new FileWriter(destFilePath));

        // 说明 : readLine 读取一行内容,但是他没有换行
        while ((line = br.readLine()) != null){
            // 每读一行就写入,边读边写
            bw.write(line);
            // 插入一个换行
            bw.newLine();
        }
    } catch (IOException e) {
        e.printStackTrace();
    }finally {
        // 关闭流
        try {
            if (br != null) {
                br.close();
            }
            if (bw != null){
                bw.close();
            }
        }catch (IOException e){
            e.printStackTrace();
        }
    }

}
相关推荐
kyriewen4 小时前
Anthropic 估值逼近万亿美元,Claude Sonnet 5 + Claude Science 一天两连发
前端·ai编程·claude
小徐_23335 小时前
Wot UI 2.2.0 发布:Button 新增 subtle,VideoPreview 预览体验继续增强
前端·微信小程序·uni-app
倔强的石头_6 小时前
《Kingbase护城河》——猎捕慢查询:执行计划的微观解析与索引调优实战
数据库
天蓝色的鱼鱼7 小时前
关于 CSS 你可能不知道的属性,但关键时刻很有用
前端·css
SelectDB8 小时前
Apache Doris Python UDF:让 SQL 直接调用 Python 生态,支撑 Agent 时代复杂业务逻辑
大数据·数据库·python
泯泷8 小时前
第 2 篇:设计第一套字节码:Opcode、Instruction 与 Constant Pool
前端·javascript·安全
妙码生花8 小时前
从 PHP 到 AI + Golang,程序员自救转型手记(十五):优化细节、网络请求封装
前端·后端·ai编程
泯泷8 小时前
第 1 篇:从 1 + 2 开始:亲手写出第一台 JSVM
前端·javascript·安全
团团崽_七分甜8 小时前
Spring Boot 核心知识点总结
前端