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

Filetouch(File baseDir, String... segments)
touch
File f = baseDir;
for (String segment : segments) {
    f = new File(f, segment);
f.getParentFile().mkdirs();
f.createNewFile();
return f;
voidtouch(File f)
Touch a file (see touch(1)).
if (!f.exists()) {
    FileWriter fw = new FileWriter(f);
    fw.close();
} else {
    f.setLastModified(System.currentTimeMillis());
voidtouch(File f)
touch
if (f.createNewFile())
    return;
f.setLastModified(System.currentTimeMillis());
voidtouch(File file)
touch
touch(file, false);
voidtouch(File file)
Touch a file, setting its last modified timestamp to current time
if (file.exists()) {
    if (!file.setLastModified(System.currentTimeMillis())) {
        throw new IOException("Could not touch file " + file.getAbsolutePath());
} else {
    try {
        File directory = file.getParentFile();
        if (!directory.exists()) {
...
booleantouch(File file)
touch
FileOutputStream fo = null;
try {
    fo = new FileOutputStream(file);
} catch (Exception e) {
    return false;
} finally {
    if (fo != null) {
        try {
...
voidtouch(File file)
Creates an empty file.
new FileOutputStream(file).close();
voidtouch(File file)
Implements the same behaviour as the "touch" utility on Unix.
if (!file.exists()) {
    OutputStream out = openOutputStream(file);
    closeQuietly(out);
boolean success = file.setLastModified(System.currentTimeMillis());
if (!success) {
    throw new IOException("Unable to set the last modification time for " + file);
voidtouch(File file)
Implements the same behaviour as the "touch" utility on Unix.
if (!file.exists()) {
    OutputStream out = new FileOutputStream(file);
    out.close();
file.setLastModified(System.currentTimeMillis());
voidtouch(File file)
touch
long timestamp = System.currentTimeMillis();
touch(file, timestamp);