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