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

voidtouch(File file)
touch
if (file.exists()) {
    return;
try {
    boolean success = file.createNewFile();
    if (!success) {
        throw new RuntimeException("can't create file. [" + file + "]");
} catch (IOException e) {
    throw new RuntimeException("can't create file. [" + file + "]");
booleantouch(File file)
touch
try {
    if (!file.exists()) {
        new FileOutputStream(file).close();
    return file.setLastModified(System.currentTimeMillis());
} catch (IOException e) {
    return false;
voidtouch(File file)
Implements the same behaviour as the "touch" utility on Unix.
if (!file.exists()) {
    OutputStream out = new FileOutputStream(file);
    closeQuietly(out);
file.setLastModified(System.currentTimeMillis());
voidtouch(File file)
Updates a file's last-modified timestamp.
if (file.exists())
    file.setLastModified(System.currentTimeMillis());
else {
    File parent = file.getParentFile();
    if (parent != null)
        parent.mkdirs();
    file.createNewFile();
voidtouch(File file)
touch
file = file.getAbsoluteFile();
FileOutputStream out = new FileOutputStream(file);
out.close();
if (!file.exists()) {
    throw new IOException("touch failed: " + file);
voidtouch(File file)
touch
if (!file.exists())
    createEmpty(file);
unguardedTouch(file);
voidtouch(File file)
touch
long currentTime = System.currentTimeMillis();
if (!file.exists()) {
    try {
        if (!file.getParentFile().exists()) {
            file.getParentFile().mkdirs();
    } catch (Exception e) {
        System.err.println("Create file failed!");
...
voidtouch(File file)
Touch (update the modification time) the given file.
file.setLastModified(System.currentTimeMillis());
booleantouch(File file, boolean createIfNeeded)
touch
if (file.exists()) {
    if (!file.setLastModified(System.currentTimeMillis())) {
        return false;
} else if (createIfNeeded) {
    try {
        return file.createNewFile();
    } catch (IOException e) {
...
voidtouch(FileFilter filter, File root, boolean recurse)
touch
if (filter.accept(root))
    root.setLastModified(new Date().getTime());
if (recurse && root.isDirectory()) {
    File[] children = root.listFiles();
    if (children != null) {
        for (int i = 0; i < children.length; i++) {
            touch(filter, children[i], recurse);