import java.io.BufferedReader;import java.io.BufferedWriter;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.FileReader;import java.io.FileWriter;import java.io.IOException;import java.io.LineNumberReader;import java.nio.Buffer;//copy picturepublic class io { public static void main(String[] args) throws IOException { FileOutputStream fos = null; FileInputStream fis = null; try { fis = new FileInputStream("e:\\4.jpg"); //源文件 fos = new FileOutputStream("e:\\5.jpg"); //复制后的文件 byte[] buf = new byte[1024]; int len = 0; while((len=fis.read(buf))!=-1) { fos.write(buf,0,len); } } catch (Exception e) { // TODO: handle exception throw new RuntimeException("复制文件失误"); } finally { try { if(fis!=null) fis.close(); } catch (Exception e2) { // TODO: handle exception throw new RuntimeException("读取关闭失败"); } try { if(fos!=null) fos.close(); } catch (Exception e2) { // TODO: handle exception throw new RuntimeException("复制关闭失败"); } } } }
//copy mp3import java.io.*;public class io { public static void main(String[] args) throws IOException { //得到当前的时间 long start = System.currentTimeMillis(); copy_mp3(); long end = System.currentTimeMillis(); System.out.println((end-start)+"毫秒"); } public static void copy_mp3() throws IOException { BufferedInputStream bufis = new BufferedInputStream(new FileInputStream("e:\\1.mp3")); BufferedOutputStream bufos = new BufferedOutputStream(new FileOutputStream("e:\\2.mp3")); int by = 0; while((by = bufis.read())!=-1) { bufos.write(by); } bufis.close(); bufos.close(); }}