Here you can find the source of touch(File file)
Parameter | Description |
---|---|
file | a parameter |
Parameter | Description |
---|---|
IOException | an exception |
public static void touch(File file) throws IOException
//package com.java2s; //License from project: Apache License import java.io.File; import java.io.IOException; public class Main { /**/*from w ww.j ava 2 s . com*/ * Touch a file, setting its last modified timestamp to current * time * * @param file * @throws IOException */ public static void touch(File file) throws IOException { if (file.exists()) { if (!file.setLastModified(System.currentTimeMillis())) { throw new IOException("Could not touch file " + file.getAbsolutePath()); } } else { try { File directory = file.getParentFile(); if (!directory.exists()) { directory.mkdirs(); } file.createNewFile(); } catch (IOException e) { throw new IOException("Could not create file " + file.getAbsolutePath(), e); } } } }