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
相关推荐
倚肆1 天前
HttpServletResponse 与 ResponseEntity 详解anyup1 天前
支持鸿蒙!开源三个月,uView Pro 开源库近期更新全面大盘点,及未来计划Hello,C++!1 天前
linux下libcurl的https简单例子悟能不能悟1 天前
java List怎么转换为Vectoryaoxin5211231 天前
241. Java 集合 - 使用 Collections 工厂类处理集合依_旧1 天前
【玩转全栈】----Django基本配置和介绍white-persist1 天前
差异功能定位解析:C语言与C++(区别在哪里?)BBB努力学习程序设计1 天前
用Bootstrap一天搞定响应式网站:前端小白的救命稻草嘴平伊之豬1 天前
跟着AI速度cli源码三-交互问答系统用户0136087566881 天前
前端支持的主要数据类型及其使用方式