Here you can find the source of touch(String filePath)
Parameter | Description |
---|---|
filePath | the abstract path to use. |
Parameter | Description |
---|---|
IOException | if creating/modifying the file violates something. |
public static boolean touch(String filePath) throws IOException
//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) { } } }