/*mp4文件复制,字节流,字符流,高效流,4种方法总结
* D:\\java\\每日讲义\\day23\\女儿国.mp4*/
public class copyMp4 {
public static void main(String[] args) throws Exception {
String src="D:\\java\\每日讲义\\day23\\女儿国.mp4";
//mathod1(src,"D:\\c1.mp4");
mathod2(src,"D:\\c2.mp4");
mathod3(src,"D:\\c3.mp4");
mathod4(src,"D:\\c4.mp4");
}
private static void mathod4(String src, String dest) throws Exception {
FileInputStream fis=new FileInputStream(src);
BufferedInputStream bis=new BufferedInputStream(fis);
FileOutputStream fos=new FileOutputStream(dest);
BufferedOutputStream bos=new BufferedOutputStream(fos);
long t1=System.currentTimeMillis();
byte[] buf=new byte[1024];
int len;
while((len=bis.read(buf))!=-1){
bos.write(len);
}
bos.close();
fos.close();
bis.close();
fis.close();
long t2=System.currentTimeMillis();
System.out.println(t2-t1+"秒");
}
private static void mathod3(String src, String dest) throws Exception {
FileInputStream fis=new FileInputStream(src);
BufferedInputStream bis=new BufferedInputStream(fis);
FileOutputStream fos=new FileOutputStream(dest);
BufferedOutputStream bos=new BufferedOutputStream(fos);
long t1=System.currentTimeMillis();
int ch;
while((ch=bis.read())!=-1){
bos.write(ch);
}
bos.close();
bis.close();
fos.close();
fis.close();
long t2=System.currentTimeMillis();
System.out.println(t2-t1+"秒");
}
private static void mathod2(String src, String dest) throws Exception {
FileInputStream fis=new FileInputStream(src);
FileOutputStream fos=new FileOutputStream(dest);
long t1=System.currentTimeMillis();
byte[] buf=new byte[1024];
int len;
while((len=fis.read(buf))!=-1){
fos.write(len);
}
fos.close();
fis.close();
long t2=System.currentTimeMillis();
System.out.println(t2-t1+"秒");
}
private static void mathod1(String src, String dest) throws Exception {
FileInputStream fis=new FileInputStream(src);
FileOutputStream fos=new FileOutputStream(dest);
long t1=System.currentTimeMillis();
int ch;
while((ch=fis.read())!=-1){
fos.write(ch);
}
fos.close();
fis.close();
long t2=System.currentTimeMillis();
System.out.println(t2-t1+"秒");
}
}
|
|