2021-04-15

在这里插入图片描述
package task17mofang;

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 {
fr = new FileReader(“d:/a.txt”);
fw = new FileWriter(“d:/b.txt”);
System.out.println(“正在玩命的拷贝…”);
int res = 0;
while ((res = fr.read())!=-1){
fw.write(res);
}
System.out.println(“拷贝文件成功”);
} catch (IOException e) {
e.printStackTrace();
} finally {
//先建立的后关闭
try {
fw.close();
} catch (IOException e) {
e.printStackTrace();
}
try {
fr.close();
} catch (IOException e) {
e.printStackTrace();
}
}

}

}
字符流仅仅可以处理文本类的
字节流可以处理所有文件

复制视频
package task17mofang;

import java.io.*;

public class BufferedByteCopyTest {
public static void main(String[] args) {
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
try {
//1.创建BufferedInputStream类型的对象与e:/桌面右侧/哈哈/WeChat_20210330161303.mp4
//的文件关联
bis = new BufferedInputStream(new FileInputStream(“e:/桌面右侧/哈哈/WeChat_20210330161303.mp4”));
//2.创建BufferedOutputStream类型的对象与e:/桌面右侧/哈哈/WeChat_20210330161303.mp4
//的文件关联
bos = new BufferedOutputStream(new FileOutputStream(“e:/桌面右侧/哈哈/WeChat.mp4”));
//3.不断的从输入流读取数据并写入到输出流中
System.out.println(“开始拷贝”);
byte[] bArr = new byte[1024];
int res = 0;
//读入 写出
while ((res = bis.read(bArr))!=-1){
bos.write(bArr,0,res);
}
System.out.println(“拷贝文件成功”);
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
bos.close();
} catch (IOException e) {
e.printStackTrace();
}
try {
bis.close();
} catch (IOException e) {
e.printStackTrace();
}
}

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值