Java File Touch touch(File file, boolean createIfNeeded)

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

Description

touch

License

Open Source License

Declaration

public static boolean touch(File file, boolean createIfNeeded) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.*;

public class Main {

    public static boolean touch(File file, boolean createIfNeeded) {
        if (file.exists()) {
            if (!file.setLastModified(System.currentTimeMillis())) {
                return false;
            }/*from w  w  w .  j a  v  a 2 s. c  o  m*/
        } else if (createIfNeeded) {
            try {
                return file.createNewFile();
            } catch (IOException e) {
                return false;
            }
        }

        return true;
    }
}

Related

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