Java File Touch touch(File file)

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

Description

touch

License

Apache License

Declaration

public static boolean touch(File file) 

Method Source Code

//package com.java2s;
/*#######################################################
 *
 *   Maintained by Gregor Santner, 2017-
 *   https://gsantner.net//*  w  ww . ja v a  2  s .  c  o m*/
 *
 *   License: Apache 2.0
 *  https://github.com/gsantner/opoc/#licensing
 *  https://www.apache.org/licenses/LICENSE-2.0
 *
#########################################################*/

import java.io.File;

import java.io.FileOutputStream;

import java.io.IOException;

public class Main {
    public static boolean touch(File file) {
        try {
            if (!file.exists()) {
                new FileOutputStream(file).close();
            }
            return file.setLastModified(System.currentTimeMillis());
        } catch (IOException e) {
            return false;
        }
    }
}

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)
  8. touch(File file)
  9. touch(File file)