public static File createFile ( String filename ) throws SecurityException , IOException { File f = new File ( filename ) ; if ( ! f . createNewFile ( ) ) { if ( ! destroy ( f ) ) { throw new SecurityException ( "Could not destroy existing file" ) ; } if ( ! f . createNewFile ( ) ) { throw new SecurityException ( "Failed to atomically create new file" ) ; } } return f ; }
Attempts to create a new file in an atomic way . If the file already exists it if first deleted .