Java File Touch touch(File file)

Here you can find the source of touch(File file)

Description

touch

License

Apache License

Declaration

public static void touch(File file) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.File;

public class Main {

    public static void touch(File file) {
        long currentTime = System.currentTimeMillis();
        if (!file.exists()) {
            try {
                if (!file.getParentFile().exists()) {
                    file.getParentFile().mkdirs();
                }/*  w ww. j  a  v  a 2s . com*/
            } catch (Exception e) {
                System.err.println("Create file failed!");
                e.printStackTrace();
            }
        }
        boolean result = file.setLastModified(currentTime);
        if (!result) {
            System.err.println("touch failed: " + file.getName());
        }
    }

    public static void touch(String fileName) {
        File file = new File(fileName);
        touch(file);
    }

    public static void touch(File[] files) {
        for (int i = 0; i < files.length; i++) {
            touch(files[i]);
        }
    }

    public static void touch(String[] fileNames) {
        File[] files = new File[fileNames.length];
        for (int i = 0; i < fileNames.length; i++) {
            files[i] = new File(fileNames[i]);
        }
        touch(files);
    }
}

Related

  1. touch(File file)
  2. touch(File file)
  3. touch(File file)
  4. touch(File file)
  5. touch(File file)
  6. touch(File file)
  7. touch(File file, boolean createIfNeeded)
  8. touch(FileFilter filter, File root, boolean recurse)
  9. touch(final File f)