Java Utililty Methods File Touch

List of utility methods to do File Touch

Description

The list of methods to do File Touch are organized into topic(s).

Method

booleantouch(String fileName)
touch
try {
    File file = new File(fileName);
    if (file.exists() == false) {
        file.createNewFile();
    } else {
        file.setLastModified(System.currentTimeMillis());
} catch (Throwable t) {
...
booleantouch(String filePath)
Creates a blank file or updates its last modified date.
File f = new File(filePath);
FileOutputStream fos = new FileOutputStream(f, true);
fos.close();
return true;
Filetouch(String fullFilePath)
touch
if (fullFilePath == null) {
    return null;
File file = new File(fullFilePath);
file.getParentFile().mkdirs();
if (!file.exists())
    file.createNewFile();
return file;
...
Filetouch(String name)
touch
String tmpdir = System.getProperty("java.io.tmpdir");
File tmpfile = new File(tmpdir, name);
Files.touch(tmpfile);
return tmpfile;
voidtouchDir(String filePath)
touch Dir
File file = new File(filePath);
if (!file.exists()) {
    file.mkdir();
voidtouchExisting(File file)
touch Existing
if (file.exists())
    unguardedTouch(file);
FiletouchFile(File directory, String name)
touch File
File newfile = new File(directory.getAbsolutePath() + File.separator + name);
touchFile(newfile);
return newfile;
voidtouchFile(File file)
Update last modified time of a given file to the current time
long timestamp = System.currentTimeMillis();
if (!file.setLastModified(timestamp)) {
    System.err.println("Last Modified Time Update Failed");
voidtouchFile(File file)
Create an empty touch.
FileOutputStream s = new FileOutputStream(file);
try {
    s.write(file.toString().getBytes());
} finally {
    s.close();
voidtouchFile(String target)
touch File
long now = new Date().getTime();
new File(target).setLastModified(now);