1 public static void main(String[] args)throws Exception { 2 3 FileInputStream fi=new FileInputStream("e:/retire.png"); 4 BufferedInputStream in=new BufferedInputStream(fi); 5 FileOutputStream fo=new FileOutputStream("d:/ss.png"); 6 BufferedOutputStream out=new BufferedOutputStream(fo); 7 byte[] buf=new byte[1024]; 8 int len=in.read(buf);//读文件,将读到的内容放入到buf数组中,返回的是读到的长度 9 10 while(len!=-1){ 11 out.write(buf, 0, len); 12 len=in.read(buf); 13 } 14 out.close(); 15 fo.close(); 16 in.close(); 17 fi.close(); 18 }