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();
}
}
}
BufferedWriter(废稿)
赛博源2024-12-24 14:20
相关推荐
程序员黑豆19 分钟前
Java类型推断完全指南:从var到菱形运算符,掌握使用限制与最佳实践To_OC1 小时前
踩了个 TS 的坑之后,我终于把 type 和 interface 掰明白了GreenTea1 小时前
深度解读 Anthropic 多智能体报告:更强的模型 ≠ 更好的协调风流 少年1 小时前
Spring AI 2.0:Memory码匠许师傅1 小时前
【C++ 面试真题】聊聊 C++ 的移动语义与右值引用浮生望1 小时前
前端API工程化:用 Mock 数据与 Axios 配置实现独立于后端的并行开发2603_965148112 小时前
如何解析JSON数据?API返回的商品信息处理教程ltl2 小时前
RocksDB 经典故障排查:L0、compaction 与 write stall万少2 小时前
给 DeepSeek Harness 装个"应用商店":一条命令,595 个插件随你逛小席是个热心肠2 小时前
AI相关的自我学习