package FileCopy;
import java.io.*;
/**
* Created by me on 2017/4/23.
*/
public class Streamdemo {
public static void copy(File src,File dst) throws IOException {
FileInputStream ins=new FileInputStream(src);
FileOutputStream outs=new FileOutputStream(dst);
long start=System.currentTimeMillis();
/* int data=-1;
while((data=ins.read())!=-1){
outs.write(data);
}
ins.close();
outs.close();*/
byte []buf=new byte[1024*1024]; //增加缓冲区 改进版
int len=0; //注意为小写byte
while((len=ins.read(buf))!=-1){
outs.write(buf);
}
long end=System.currentTimeMillis();
System.out.println("用时"+(end-start));
ins.close();
outs.close();
}
import java.io.*;
/**
* Created by me on 2017/4/23.
*/
public class Streamdemo {
public static void copy(File src,File dst) throws IOException {
FileInputStream ins=new FileInputStream(src);
FileOutputStream outs=new FileOutputStream(dst);
long start=System.currentTimeMillis();
/* int data=-1;
while((data=ins.read())!=-1){
outs.write(data);
}
ins.close();
outs.close();*/
byte []buf=new byte[1024*1024]; //增加缓冲区 改进版
int len=0; //注意为小写byte
while((len=ins.read(buf))!=-1){
outs.write(buf);
}
long end=System.currentTimeMillis();
System.out.println("用时"+(end-start));
ins.close();
outs.close();
}
}
package FileCopy;
import java.io.File;
import java.io.IOException;
/**
* Created by me on 2017/4/23.
*/
public class Filecopy {
public static void main(String[] args) throws IOException {
Streamdemo.copy(new File(""),new File(""));
}
}