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
相关推荐
wuhen_n35 分钟前
网络请求在Vite层的代理与Mock:告别跨域和后端依赖haixingtianxinghai38 分钟前
Redis的定期删除和惰性删除资深web全栈开发39 分钟前
PostgreSQL Schema 最佳实践:架构师的命名与组织艺术麦聪聊数据2 小时前
利用实时数据管道与 SQL2API 重构企业自动化审计架构麦聪聊数据2 小时前
重构开放生态:利用 QuickAPI 跨越遗留系统与敏捷交付的工程实践云原生指北3 小时前
GitHub Copilot SDK 入门:五分钟构建你的第一个 AI Agent用户69371750013845 小时前
Google 正在“收紧侧加载”:陌生 APK 安装或需等待 24 小时蓝帆傲亦6 小时前
Web 前端搜索文字高亮实现方法汇总用户69371750013846 小时前
Room 3.0:这次不是升级,是重来百结2146 小时前
Mysql数据库操作