import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
public class testZy2 {
public static void main(String[] args) throws IOException {
//这段代码放在程序执行前
long begin = System.currentTimeMillis();
duqu("G:\\myeclipse-2017-ci-5-offline-installer-windows.exe","D:\\123\\001.exe");
//调用duqu方法读出文件目标文件内容
// 这段代码放在程序执行后
long end = System.currentTimeMillis() - begin;
System.out.println("耗时:" + end + "毫秒");
}
private static void duqu(String path,String path1) throws FileNotFoundException, IOException {
FileInputStream fi = new FileInputStream(path);
//利用InPutStreamd读取文件内容
File file1 = new File(path);
//new一个File对象以获取文档长度
int flen = (int) file1.length();
//获取文档长度,其长度为flen
//
File file = new File(path1);
//创建要写入的文件夹
//
file.createNewFile();
//创建要写入的文件夹
FileOutputStream fo = new FileOutputStream(path1); //new一个OutPutStream对象
for(int i =0;i<flen;i++){
int data = fi.read();
fo.write(data);
}
System.out.println("按字节复制完毕。。。");
//关闭流
fi.close();
fo.close();
}
}