Here you can find the source of touch(final File f)
public static void touch(final File f) throws IOException
//package com.java2s; /*/*ww w . ja va2s . c om*/ The OpenTRV project licenses this file to you under the Apache Licence, Version 2.0 (the "Licence"); you may not use this file except in compliance with the Licence. You may obtain a copy of the Licence at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the Licence is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Licence for the specific language governing permissions and limitations under the Licence. Author(s) / Copyright (s): Damon Hart-Davis 2015 */ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; public class Main { /**Lock object for touch and rate-limit to serialise operations per process (or class loader). * This aims to reduce the chance of a race within the file system. * <p> * This may also make an in-process cache plausible. */ private static final Object touchLock = new Object(); /**Touch the specified file, creating if necessary. */ public static void touch(final File f) throws IOException { synchronized (touchLock) { if (!f.exists()) { new FileOutputStream(f, true).close(); } else { f.setLastModified(System.currentTimeMillis()); } } } }