Java File Touch touch(String filePath)

Here you can find the source of touch(String filePath)

Description

Creates a blank file or updates its last modified date.

License

Open Source License

Parameter

Parameter Description
filePath the abstract path to use.

Exception

Parameter Description
IOException if creating/modifying the file violates something.

Return

true if the file was made/updated, false otherwise.

Declaration

public static boolean touch(String filePath) throws IOException 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2009-2016 Black Rook Software
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser Public License v2.1
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
 ******************************************************************************/

import java.io.*;

public class Main {
    /**/*from  www . j  a va  2 s  .  co m*/
     * Creates a blank file or updates its last modified date.
     * @param filePath   the abstract path to use.
     * @return true if the file was made/updated, false otherwise.
     * @throws IOException if creating/modifying the file violates something.
     */
    public static boolean touch(String filePath) throws IOException {
        File f = new File(filePath);
        FileOutputStream fos = new FileOutputStream(f, true);
        fos.close();
        return true;
    }

    /**
     * Attempts to close a {@link Closeable} object.
     * If the object is null, this does nothing.
     * @param c the reference to the closeable object.
     * @since 2.3.0
     */
    public static void close(Closeable c) {
        if (c == null)
            return;
        try {
            c.close();
        } catch (IOException e) {
        }
    }

    /**
     * Attempts to close an {@link AutoCloseable} object.
     * If the object is null, this does nothing.
     * @param c the reference to the AutoCloseable object.
     * @since 2.31.1
     */
    public static void close(AutoCloseable c) {
        if (c == null)
            return;
        try {
            c.close();
        } catch (Exception e) {
        }
    }
}

Related

  1. touch(String answers)
  2. touch(String f)
  3. touch(String file)
  4. touch(String file)
  5. touch(String fileName)
  6. touch(String fullFilePath)
  7. touch(String name)
  8. touchDir(String filePath)
  9. touchExisting(File file)