将数据从硬盘写入内存,再从内存写入硬盘(拷贝)详解
将数据从硬盘写入内存,再从内存写入硬盘(拷贝)详细解析
package com.liujinghe.c_lianxi.p1;
import java.io.*;
public class Demo3 {
public static void main(String[] args) throws IOException {
//将文件从一个位置copy到另一个位置
//1创建文件类对象
//C:\Users\Administrator\Desktop\疫情期间资料\视频\day17
long start = System.currentTimeMillis();
File file = new File("C:\\Users\\Administrator\\Desktop\\疫情期间资料\\视频\\day17\\2ArrayLine增删查内存分析.wmv");
//创建输入缓冲流
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
//创建输出缓冲流
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(new File("D:/file/aaa/2ArrayLine增删查内存分析.wmv")));
//创建缓冲数组
byte [] buf = new byte[1024*4];
//读写数据
int length = -1;
while((length=bis.read(buf))!=-1) {
bos.write(buf,0,length);
}
//关闭流资源
bis.close();
bos.close();
long end = System.currentTimeMillis();
System.out.println("总共用时:"+(end-start));
}
}