public static String appendSystemtimeToFilename ( final File fileToRename , final Date add2Name ) { final String format = "HHmmssSSS" ; String sysTime = null ; if ( null != add2Name ) { final DateFormat df = new SimpleDateFormat ( format ) ; sysTime = df . format ( add2Name ) ; } else { final DateFormat df = new SimpleDateFormat ( format ) ; sysTime = df . format ( new Date ( ) ) ; } final String fileName = fileToRename . getName ( ) ; final int ext_index = fileName . lastIndexOf ( "." ) ; final String ext = fileName . substring ( ext_index , fileName . length ( ) ) ; String newName = fileName . substring ( 0 , ext_index ) ; newName += "_" + sysTime + ext ; return newName ; }
Returns the filename from the given file with the systemtime .