Java Path Create nio createIncrNonExistentFilename(final Path parent, final String prefix, final String suffix)

Here you can find the source of createIncrNonExistentFilename(final Path parent, final String prefix, final String suffix)

Description

Create a non existent filename.

License

Open Source License

Parameter

Parameter Description
parent Parent directory
prefix File's prefix
suffix File's suffix

Return

Path

Declaration

public static Path createIncrNonExistentFilename(final Path parent, final String prefix, final String suffix) 

Method Source Code

//package com.java2s;
/*//from w w w. ja  va  2s . co m
 * Copyright (C) 2013 Fabien Vauchelles (fabien_AT_vauchelles_DOT_com).
 *
 * This library 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, 29 June 2007, of the License, or (at your option) any later version.
 *
 * This library 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.nio.file.Files;
import java.nio.file.Path;

public class Main {
    /**
     * Create a non existent filename.
     *
     * @param parent Parent directory
     * @param prefix File's prefix
     * @param suffix File's suffix
     * @return Path
     */
    public static Path createIncrNonExistentFilename(final Path parent, final String prefix, final String suffix) {
        int i = 1;
        Path result;
        do {
            result = parent.resolve(prefix + i + suffix);
            ++i;
        } while (Files.exists(result));

        return result;
    }
}

Related

  1. createFoldersIfNecessary(String workspacePath)
  2. createFullURI(String val, Path parent)
  3. createGlobMatcher(final Path path)
  4. createHeader(Path newFile)
  5. createHiddenFile(String filePath)
  6. createJarFile(Path directory, String name, Optional manifest, Class[] classesToAdd, Map filesToAdd)
  7. createJSONFileIfNotExists(Path path)
  8. createLanguageStructure(final String lang, final Path docRootFolder)
  9. createList(Iterable dirs)