code: private final static void copy(File fromFile, File toFile)
              throws IOException {
          FileInputStream in = new FileInputStream(fromFile);
          FileOutputStream out = new FileOutputStream(toFile);
          BufferedInputStream inBuffer = new BufferedInputStream(in);
          BufferedOutputStream outBuffer = new BufferedOutputStream(out);
  
          int theByte = 0;
  
          while ((theByte = inBuffer.read()) > -1) {
              outBuffer.write(theByte);
          }
  
          outBuffer.close();
          inBuffer.close();
          out.close();
          in.close();
  
          // cleanupif files are not the same length
          if (fromFile.length() != toFile.length()) {
              toFile.delete();
  
              throw new IOException("Copy failed: source file length="
                      + fromFile.length() + ", target file length="
                      + toFile.length());
          }
      }
docs: Copy a File
  
  @param fromFile
  The existing File
  @param toFile
  The new File
  @throws IOException
  if any problems are encountered