Java tutorial
//package com.java2s; import java.io.File; public class Main { public static File findUnusedFilename(File saveDirectory, String name, String extension) { File file; String str = ""; int i = 0; do { file = new File(saveDirectory, name + str + extension); str = Integer.toString(i++); } while (file.exists()); return file; } }