public final static void writeAndBackup(File file, String content) { try { DateFormat backupDF = new SimpleDateFormat("ddMMyy_hhmmss"); File backupDirectory = checkBackupDirectory(file); File original = new File(file.getAbsolutePath()); File backup = new File(backupDirectory, original.getName() + "." + backupDF.format(new Date())); if (log.isDebugEnabled()) { log.debug("Backup file is " + backup); } original.renameTo(backup); BufferedWriter out = new BufferedWriter(new FileWriter(file)); out.write(content); out.close(); } catch (FileNotFoundException e) { log.warn("File not found", e); } catch (IOException e) { log.error(e); } } }
public final static void writeAndBackup(File file, String content) { try { DateFormat backupDF = new SimpleDateFormat("ddMMyy_hhmmss"); File backupDirectory = checkBackupDirectory(file); File original = new File(file.getAbsolutePath()); File backup = new File(backupDirectory, original.getName() + "." + backupDF.format(new Date())); if (log.isDebugEnabled()) { log.debug("Backup file is " + backup); } original.renameTo(backup); BufferedWriter out = new BufferedWriter(new FileWriter(file)); out.write(content); out.close(); } catch (FileNotFoundException e) { log.warn("File not found", e); } catch (IOException e) { log.error(e); } } }