public static void secureDelete(File file) throws IOException {
  log.debug("Start of secureDelete");
  RandomAccessFile raf=null;
  if (file != null && file.exists()) {
    try {
      file.setWritable(true);
      System.gc();
      long length=file.length();
      raf=new RandomAccessFile(file,"rws");
      raf.seek(0);
      raf.getFilePointer();
      int pos=0;
      while (pos < length) {
        raf.write(SECURE_DELETE_FILL_BYTES);
        pos+=SECURE_DELETE_FILL_BYTES.length;
      }
    }
  finally {
      if (raf != null) {
        raf.close();
        raf=null;
      }
    }
    boolean deleteSuccess=file.delete();
    log.debug("Result of delete of file '" + file.getAbsolutePath() + "' was "+ deleteSuccess);
  }
  log.debug("End of secureDelete");
}

public static void secureDelete ( File file ) throws IOException { log . debug ( "Start of secureDelete" ) ; RandomAccessFile raf = null ; if ( file != null && file . exists ( ) ) { try { file . setWritable ( true ) ; System . gc ( ) ; long length = file . length ( ) ; raf = new RandomAccessFile ( file , "rws" ) ; raf . seek ( 0 ) ; raf . getFilePointer ( ) ; int pos = 0 ; while ( pos < length ) { raf . write ( SECURE_DELETE_FILL_BYTES ) ; pos += SECURE_DELETE_FILL_BYTES . length ; } } finally { if ( raf != null ) { raf . close ( ) ; raf = null ; } } boolean deleteSuccess = file . delete ( ) ; log . debug ( "Result of delete of file '" + file . getAbsolutePath ( ) + "' was " + deleteSuccess ) ; } log . debug ( "End of secureDelete" ) ; }
delete a file with an overwrite of all of the data . set bit patterns are used rather than random numbers to avoid a futex_wait_queue_me error on linux systems ( related to / dev / random usage )
