public static boolean destroy ( File file ) { if ( ! file . exists ( ) ) return false ; RandomAccessFile f = null ; long size = file . length ( ) ; try { f = new RandomAccessFile ( file , "rw" ) ; long rec = size / DMSG . length ( ) ; int left = ( int ) ( size - rec * DMSG . length ( ) ) ; while ( rec != 0 ) { f . write ( DMSG . getBytes ( ) , 0 , DMSG . length ( ) ) ; rec -- ; } if ( left > 0 ) { f . write ( DMSG . getBytes ( ) , 0 , left ) ; } } catch ( Exception e ) { return false ; } finally { try { if ( f != null ) f . close ( ) ; } catch ( Exception e ) { } } return file . delete ( ) ; }
Overwrites the contents of the file with a random string and then deletes the file .