Here you can find the source of touch(File file)
Parameter | Description |
---|---|
file | The file |
Parameter | Description |
---|---|
IOException | In case of an I/O error |
public static void touch(File file) throws IOException
//package com.java2s; /**//from w w w . j av a 2s.co m * Copyright 2011-2016 Three Crickets LLC. * <p> * The contents of this file are subject to the terms of the LGPL version 3.0: * http://www.gnu.org/copyleft/lesser.html * <p> * Alternatively, you can obtain a royalty free commercial license with less * limitations, transferable or non-transferable, directly from Three Crickets * at http://threecrickets.com/ */ import java.io.File; import java.io.IOException; public class Main { /** * Updates a file's last-modified timestamp. * <p> * If the file doesn't exist, it is created as an empty file, including * necessary parent directories. * * @param file * The file * @throws IOException * In case of an I/O error */ public static void touch(File file) throws IOException { if (file.exists()) file.setLastModified(System.currentTimeMillis()); else { File parent = file.getParentFile(); if (parent != null) parent.mkdirs(); file.createNewFile(); } } }