Java运用缓冲流进行拷贝文本文件
代码如下:
import org.junit.Test;
import java.io.*;
import java.text.SimpleDateFormat;
public class E {
@Test
public void copy() throws IOException {
long start=System.currentTimeMillis();
BufferedInputStream bis=new BufferedInputStream(new FileInputStream("d://1.wmv"));//从D盘读取出数据
BufferedOutputStream bos=new BufferedOutputStream(new FileOutputStream("e://1.wmv"));//写入另一个文本文件中
byte []buffer=new byte[1024];
int n=-1;
while((n=bis.read(buffer))!=-1){
bos.write(buffer);
}
long end=System.currentTimeMillis();
SimpleDateFormat sdf=new SimpleDateFormat("ss");
System.out.println(sdf.format(end-start));//显示整个拷贝过程时间
}
}