Java Path Delete nio deleteLockFile(Path logFile)

Here you can find the source of deleteLockFile(Path logFile)

Description

Removes any lck files for the given log file.

License

Open Source License

Parameter

Parameter Description
logFile the file for which the lock should be deleted

Exception

Parameter Description
IOException if the lock file could not be deleted

Declaration

public static void deleteLockFile(Path logFile) throws IOException 

Method Source Code


//package com.java2s;
/*/*w w  w.  j  a v a  2s  .co  m*/
 *     BasePlugin
 *   Copyright (C) 2014 Viciouss <http://www.doncarnage.de>
 *
 *   This program is free software; you can redistribute it and/or
 *   modify it under the terms of the GNU Lesser General Public
 *   License as published by the Free Software Foundation; either
 *   version 3 of the License, or (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *   Lesser General Public License for more details.
 *
 *   You should have received a copy of the GNU Lesser General Public
 *   License along with this library; if not, write to the Free Software
 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301
 *   USA
 */

import java.io.IOException;

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

public class Main {
    /**
     * Removes any lck files for the given log file.
     *
     * @param logFile the file for which the lock should be deleted
     * @throws IOException if the lock file could not be deleted
     */
    public static void deleteLockFile(Path logFile) throws IOException {
        String lockFileName = logFile.getFileName().toString().concat(".lck");
        Path parent = logFile.getParent();
        Path lockFile;
        if (parent == null) {
            lockFile = Paths.get(lockFileName);
        } else {
            lockFile = parent.resolve(lockFileName);
        }

        Files.deleteIfExists(lockFile);
    }
}

Related

  1. deleteFilesIgnoringExceptions(final Path... files)
  2. deleteFilesRecursively(Path path, final PathMatcher pathMatcher)
  3. deleteIfExists(Path thePath)
  4. deleteIfExists(Path value)
  5. deleteIndexBeforeStart(String basePath)
  6. deleteNotEmptyDirectory(Path path)
  7. deleteOnExit(Path path)
  8. deletePath(Path path)
  9. deletePathRecursively(String path)