Example usage for java.nio.file Files notExists

List of usage examples for java.nio.file Files notExists

Introduction

In this page you can find the example usage for java.nio.file Files notExists.

Prototype

public static boolean notExists(Path path, LinkOption... options) 

Source Link

Document

Tests whether the file located by this path does not exist.

Usage

From source file:ws.michalski.velogen.VeloGenManager.java

/**
 * Liefert Output-Path fr generierte Dateien
 * /*from   ww  w  .ja  va  2s. c  o  m*/
 * 1. Es wird geprft, ob Parameter -op gesetzt ist, sonst
 * 2. wird geprft, ob config diese Information enthlt, sonst
 * 3. wird Unterverzeichnis ./output genutzt.
 * 
 * 
 * @return
 */
public String getOutputPath() {

    String outputPath = null;

    if (veloCmd.getCommonParam().getOutputPath() != null) {
        outputPath = veloCmd.getCommonParam().getOutputPath();
    } else if (config.getOutputPath() != null) {
        outputPath = config.getOutputPath();
    } else {
        outputPath = SystemUtils.USER_DIR + SystemUtils.FILE_SEPARATOR + "output";
    }

    Path path = Paths.get(outputPath);

    if (Files.notExists(path, LinkOption.NOFOLLOW_LINKS)
            || !Files.isDirectory(path, LinkOption.NOFOLLOW_LINKS)) {
        logger.error("Output path error");
        // TODO: Exception
    }

    if (logger.isDebugEnabled()) {
        logger.debug("Path " + path.toAbsolutePath().normalize().toString());
    }

    return path.toAbsolutePath().normalize().toString();
}

From source file:com.cyc.corpus.nlmpaper.AIMedOpenAccessPaper.java

private Optional<Path> getZipArchive(boolean cached) {
    try {/*from  w ww.ja v a 2 s  .c o  m*/
        Path cachedFilePath = cachedArchivePath();
        Path parentDirectoryPath = cachedFilePath.getParent();

        // create the parent directory it doesn't already exist
        if (Files.notExists(parentDirectoryPath, LinkOption.NOFOLLOW_LINKS)) {
            Files.createDirectory(parentDirectoryPath);
        }

        // if cached file already exist - return it, no download necessary
        if (cached && Files.exists(cachedFilePath, LinkOption.NOFOLLOW_LINKS)) {
            return Optional.of(cachedFilePath.toAbsolutePath());
        }

        // otherwise, download the file
        URL url = new URL(PROTEINS_URL);
        Files.copy(url.openStream(), cachedFilePath, StandardCopyOption.REPLACE_EXISTING);
        return Optional.of(cachedFilePath.toAbsolutePath());

    } catch (MalformedURLException ex) {
        LOG.log(Level.SEVERE, ex.getMessage(), ex);
    } catch (IOException ex) {
        LOG.log(Level.SEVERE, ex.getMessage(), ex);
    }

    return Optional.empty();
}