说明 先对E盘Class文件里对1.jpg图片进行读到内存中再把1.jpg从内存写入F盘的Class文件中这里我做了个小添加,就是在运行前测试了毫秒值,运行后又测了毫秒值,对这次的运行时间做了个计算 public class Day3IO { public static void main(String[] args) throws IOException { long s = System.currentTimeMillis();//测试此时的毫秒值 FileInputStream fs = new FileInputStream("E:\\Class\\1.jpg"); FileOutputStream fsp = new FileOutputStream("F:\\Class\\1.jpg"); //读取字节数多的文件时,使用byte[] byte[] bytes = new byte[1024]; int len = 0; while ((len = fs.read(bytes))!=-1){ fsp.write(bytes,0,len);//写入,此时直接从0字节输出到最后一个字节,提高读写速度 } fsp.close(); fs.close(); long e = System.currentTimeMillis();//运行结束时的毫秒值 System.out.println("运行的时间为: "+(e-s)+"毫秒"); } }