public boolean makeBackupFile(String directory,File file){
  if (file == null) {
    log.info("No file to backup");
  }
 else   if (file.canWrite()) {
    String backupFullName=directory + File.separator + createFileNameWithDate(file.getName());
    if (log.isDebugEnabled()) {
      log.debug("new backup file: " + backupFullName);
    }
    File backupFile=findFile(backupFullName);
    if (backupFile != null) {
      if (backupFile.delete()) {
        if (log.isDebugEnabled()) {
          log.debug("deleted backup file " + backupFullName);
        }
      }
    }
 else {
      backupFile=new File(backupFullName);
    }
    File parentDir=backupFile.getParentFile();
    if (!parentDir.exists()) {
      if (log.isDebugEnabled()) {
        log.debug("creating backup directory: " + parentDir.getName());
      }
      if (!parentDir.mkdirs()) {
        log.error("backup directory not created");
        return false;
      }
    }
    if (file.renameTo(new File(backupFullName))) {
      if (log.isDebugEnabled()) {
        log.debug("created new backup file " + backupFullName);
      }
    }
 else {
      if (log.isDebugEnabled()) {
        log.debug("could not create backup file " + backupFullName);
      }
      return false;
    }
  }
  return true;
}

public boolean makeBackupFile ( String directory , File file ) { if ( file == null ) { log . info ( "No file to backup" ) ; } else if ( file . canWrite ( ) ) { String backupFullName = directory + File . separator + createFileNameWithDate ( file . getName ( ) ) ; if ( log . isDebugEnabled ( ) ) { log . debug ( "new backup file: " + backupFullName ) ; } File backupFile = findFile ( backupFullName ) ; if ( backupFile != null ) { if ( backupFile . delete ( ) ) { if ( log . isDebugEnabled ( ) ) { log . debug ( "deleted backup file " + backupFullName ) ; } } } else { backupFile = new File ( backupFullName ) ; } File parentDir = backupFile . getParentFile ( ) ; if ( ! parentDir . exists ( ) ) { if ( log . isDebugEnabled ( ) ) { log . debug ( "creating backup directory: " + parentDir . getName ( ) ) ; } if ( ! parentDir . mkdirs ( ) ) { log . error ( "backup directory not created" ) ; return false ; } } if ( file . renameTo ( new File ( backupFullName ) ) ) { if ( log . isDebugEnabled ( ) ) { log . debug ( "created new backup file " + backupFullName ) ; } } else { if ( log . isDebugEnabled ( ) ) { log . debug ( "could not create backup file " + backupFullName ) ; } return false ; } } return true ; }
move original file to backup directory .
