Java tutorial
//package com.java2s; import java.io.File; public class Main { private static boolean deleteFileSafely(File file) { if (file != null) { String tmpPath = file.getAbsolutePath() + System.currentTimeMillis(); File tmp = new File(tmpPath); boolean result = file.renameTo(tmp); return result && tmp.delete(); } return false; } }