文件拷贝过程中使用文件流、缓冲流、转换流以及速率比较
2015-01-27 17:10
281 查看
package com.oracle.huanchongliu;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import org.junit.Test;
public class Test_huanchong {
/**
* 实用了文件流和缓冲流
*/
@Test
public void test1(){
File file=new File("E:\\冰与火之歌\\[电影天堂www.dy2018.net]冰与火之歌:权力的游戏第一季05集中英双字[1024分辨率].RMVB");
File file1=new File("E:\\复制1.RMVB");
long t1=System.currentTimeMillis();
long t2=0;
FileInputStream fis=null;
FileOutputStream fos=null;
BufferedInputStream bis=null;
BufferedOutputStream bos=null;
try {
fis=new FileInputStream(file);
bis=new BufferedInputStream(fis);
fos=new FileOutputStream(file1);
bos=new BufferedOutputStream(fos);
byte[] by=new byte[1024];
int len=1024;
while((len=bis.read(by))!=-1){
bos.write(by, 0, len);
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
t2=System.currentTimeMillis();
System.out.println(t2-t1);
}
/**
* 什么也不使用的,只用了文件流
*/
@Test
public void test2(){
File file=new File("E:\\冰与火之歌\\[电影天堂www.dy2018.net]冰与火之歌:权力的游戏第一季05集中英双字[1024分辨率].RMVB");
File file1=new File("E:\\复制2.RMVB");
long t1=System.currentTimeMillis();
long t2=0;
FileInputStream fis=null;
FileOutputStream fos=null;
try {
fis=new FileInputStream(file);
fos=new FileOutputStream(file1);
byte[] by=new byte[1024];
int len=1024;
while((len=fis.read(by))!=-1){
fos.write(by, 0, len);
fos.flush();
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
t2=System.currentTimeMillis();
System.out.println(t2-t1);
}
/**
* 使用了文件流、缓冲流、转换流
*/
@Test
public void test3(){
File file=new File("E:\\冰与火之歌\\[电影天堂www.dy2018.net]冰与火之歌:权力的游戏第一季05集中英双字[1024分辨率].RMVB");
File file1=new File("E:\\复制3.RMVB");
long t1=System.currentTimeMillis();
long t2=0;
FileInputStream fis=null;
InputStreamReader isr=null;
BufferedReader bis=null;
FileOutputStream fos=null;
OutputStreamWriter osw=null;
BufferedWriter bos=null;
try {
fis=new FileInputStream(file);
isr=new InputStreamReader(fis);
bis=new BufferedReader(isr);
fos=new FileOutputStream(file1);
osw=new OutputStreamWriter(fos);
bos=new BufferedWriter(osw);
char[] by=new char[1024];
int len=1024;
while((len=bis.read(by))!=-1){
bos.write(by,0,len);
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
t2=System.currentTimeMillis();
System.out.println(t2-t1);
}
}
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import org.junit.Test;
public class Test_huanchong {
/**
* 实用了文件流和缓冲流
*/
@Test
public void test1(){
File file=new File("E:\\冰与火之歌\\[电影天堂www.dy2018.net]冰与火之歌:权力的游戏第一季05集中英双字[1024分辨率].RMVB");
File file1=new File("E:\\复制1.RMVB");
long t1=System.currentTimeMillis();
long t2=0;
FileInputStream fis=null;
FileOutputStream fos=null;
BufferedInputStream bis=null;
BufferedOutputStream bos=null;
try {
fis=new FileInputStream(file);
bis=new BufferedInputStream(fis);
fos=new FileOutputStream(file1);
bos=new BufferedOutputStream(fos);
byte[] by=new byte[1024];
int len=1024;
while((len=bis.read(by))!=-1){
bos.write(by, 0, len);
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
t2=System.currentTimeMillis();
System.out.println(t2-t1);
}
/**
* 什么也不使用的,只用了文件流
*/
@Test
public void test2(){
File file=new File("E:\\冰与火之歌\\[电影天堂www.dy2018.net]冰与火之歌:权力的游戏第一季05集中英双字[1024分辨率].RMVB");
File file1=new File("E:\\复制2.RMVB");
long t1=System.currentTimeMillis();
long t2=0;
FileInputStream fis=null;
FileOutputStream fos=null;
try {
fis=new FileInputStream(file);
fos=new FileOutputStream(file1);
byte[] by=new byte[1024];
int len=1024;
while((len=fis.read(by))!=-1){
fos.write(by, 0, len);
fos.flush();
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
t2=System.currentTimeMillis();
System.out.println(t2-t1);
}
/**
* 使用了文件流、缓冲流、转换流
*/
@Test
public void test3(){
File file=new File("E:\\冰与火之歌\\[电影天堂www.dy2018.net]冰与火之歌:权力的游戏第一季05集中英双字[1024分辨率].RMVB");
File file1=new File("E:\\复制3.RMVB");
long t1=System.currentTimeMillis();
long t2=0;
FileInputStream fis=null;
InputStreamReader isr=null;
BufferedReader bis=null;
FileOutputStream fos=null;
OutputStreamWriter osw=null;
BufferedWriter bos=null;
try {
fis=new FileInputStream(file);
isr=new InputStreamReader(fis);
bis=new BufferedReader(isr);
fos=new FileOutputStream(file1);
osw=new OutputStreamWriter(fos);
bos=new BufferedWriter(osw);
char[] by=new char[1024];
int len=1024;
while((len=bis.read(by))!=-1){
bos.write(by,0,len);
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
t2=System.currentTimeMillis();
System.out.println(t2-t1);
}
}
相关文章推荐
- java文件流——使用字节流拷贝文件
- 图片文件,图片文件流和BASE64加密字符串之间的转换,以及图片的BASE64加密字符串再jsp上如何显示
- w_文件流,缓冲流,二进制流复制文件哪个比较快!
- 使用FileStream文件流实现大文件的拷贝
- 最全PDF转换器使用方法以及功能介绍 文件转换不再困难
- 使用mp4v2将H264+AAC合成mp4文件以及调试过程
- 在安卓机上测试内联汇编和直接写成.s文件以及C语言的速率比较
- 使用文件流(FileStream)实现大文件的拷贝
- ueditor1.4.3配置过程(包含单独上传文件以及图片的使用)
- 图片文件,图片文件流和BASE64加密字符串之间的转换,以及图片的BASE64加密字符串再jsp上如何显示
- 请使用C#的文件流来拷贝文件
- java文件流——使用字符流拷贝文件
- 使用字节流复制文件的四种方式以及效率比较
- 使用Java解析svg文件,以及将获取的Element转换成String
- NO.23 使用openssl-0.9.8b将CER、PFX转换成PEM文件(含openssl Win64环境安装过程)
- ueditor1.4.3配置过程(包含单独上传文件以及图片的使用),ueditor1.4.3上传配置(转 http://www.bkjia.com/webzh/1001016.html)
- linux shell 编程1文件权限检测、字符串比较判断、数值大小比较、时间获取以及单引号双引号反引号等的使用
- 分别使用文件流和缓冲流复制一个长度大于100MB的视频文件,并观察效率的差异
- pyuic的参数,以及如何使用由ui转换的.py文件
- 使用File类判断文件是否存在以及创建,拷贝和移动文件