Here you can find the source of makeUnique(Path basePath, String baseName)
public static Path makeUnique(Path basePath, String baseName)
//package com.java2s; //License from project: Apache License import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; public class Main { /**//from w w w.j a v a 2 s . c o m * If the given path contains a file baseName a number is added as a suffix. */ public static Path makeUnique(Path basePath, String baseName) { Path desiredPath = Paths.get(basePath.toString(), baseName); int suffix = 0; while (Files.exists(desiredPath)) { desiredPath = Paths.get(basePath.toString(), baseName + "_" + (suffix++)); } return desiredPath; } }