public static void touch ( File file ) throws FileNotFoundException { if ( ! file . exists ( ) ) { OutputStream out = new FileOutputStream ( file ) ; try { out . close ( ) ; } catch ( IOException e ) { // Ignore. } } file . setLastModified ( System . currentTimeMillis ( ) ) ; }
Implements the same behavior as the touch utility on Unix . It creates a new file with size 0 byte or if the file exists already it is opened and closed without modifying it but updating the file date and time .