|NO.Z.00078|——————————|BigDataEnd|——|Java&IO流.V05|——|Java.v05|IO流.v05|文件字符流|实现文件拷贝|
一、文件字符流实现文件的拷贝:编程代码
package com.yanqi.task17;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class FileCharCopyTest {
public static void main(String[] args) {
FileReader fr = null;
FileWriter fw = null;
try {
// 1.创建FileReader类型的对象与d:/a.txt文件关联
fr = new FileReader("d:/a.txt");
//fr = new FileReader("d:/03 IO流的框架图.png");
// 2.创建FileWriter类型的对象与d:/b.txt文件关联
fw = new FileWriter("d:/b.txt");
//fw = new FileWriter("d:/IO流的框架图.png"); 拷贝图片文件失败!!!
// 3.不断地从输入流中读取数据内容并写入到输出流中
System.out.println("正在玩命地拷贝...");
int res = 0;
while ((res = fr.read()) != -1) {
fw.write(res);
}
System.out.println("拷贝文件成功!");
} catch (IOException e) {
e.printStackTrace();
} finally {
// 4.关闭流对象并释放有关的资源
if (null != fw) {
try {
fw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (null != fr) {
try {
fr.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
二、编译打印
D:\JAVA\jdk-11.0.2\bin\java.exe "-javaagent:D:\IntelliJIDEA\IntelliJ IDEA 2019.3.3\lib\idea_rt.jar=51938:D:\IntelliJIDEA\IntelliJ IDEA 2019.3.3\bin" -Dfile.encoding=UTF-8 -classpath E:\NO.Z.10000——javaproject\NO.H.00001.javase\javase\out\production\javase com.yanqi.task17.FileCharCopyTest
正在玩命地拷贝...
拷贝文件成功!
Process finished with exit code 0
Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart
——W.S.Landor
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!