Here you can find the source of createIncrNonExistentFilename(final Path parent, final String prefix, final String suffix)
Parameter | Description |
---|---|
parent | Parent directory |
prefix | File's prefix |
suffix | File's suffix |
public static Path createIncrNonExistentFilename(final Path parent, final String prefix, final String suffix)
//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; } }