BufferedInputStream&BufferedOutputStream
2024-08-30 05:11:59
使用字符缓冲区相关实现copy文件;
public static void main(String[] args) {
//创建文件对象指定要拷贝的文件路径(源文件),文件须存在,测试用例不做判断
File srcFile=new File("E:\\CloudMusic\\mp3\\a.mp3");
//创建文件对象指定文件拷贝的目标路径
File destFile=new File("d:\\test1.mp3");
System.out.println("正在复制文件.......");
try {
//创建文件输入流对象
FileInputStream fin=new FileInputStream(srcFile);
//创建缓冲区输入流对象(加快文件的读取效率)
BufferedInputStream bin=new BufferedInputStream(fin); //创建文件输出流对象
FileOutputStream fout=new FileOutputStream(destFile);
//创建缓冲区输出流对象,加快文件流的输出效率
BufferedOutputStream bout=new BufferedOutputStream(fout); //声明int类型的变量准备逐字节拷贝文件
int b;
while((b=bin.read())!=-){
bout.write(b);//写出字节到文件
} bout.flush();
bout.close();
bin.close();
System.out.println("文件拷贝结束!");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
最新文章
- 设置JDK环境变量(linux版)
- spark编写word count
- 用centos光盘安装RPM包的方法
- cocos2dx 安卓编译问题收集
- python 中 sorted() 和 list.sort() 的用法
- Windows 7 32位上硬盘安装linux[ubuntu13.04] 双系统
- HttpClient设置代理,超时,以及得到cookies
- Oracle 监听配置详解(转载)
- python高级编程之超类02:super的缺陷
- 基于visual Studio2013解决面试题之0905子串数量
- 微信iOS收款到账语音提醒开发总结
- PDA(Windows Mobile)调用远程WebService
- windows使用im4java 提示FileNotFoundException
- LeetCode-63. 不同路径 II
- reduce方法简单实现数组中对象去重
- GPUImage中饱和度调整的实现——GPUImageSaturationFilter
- Google Kickstart Round.B C. Diverse Subarray
- java的redis工具类
- 《剑指offer》第十九题(正则表达式匹配)
- vsftp 500 OOPS: cannot change directory:/home/xyp