Java tutorial
//package com.java2s; import java.io.File; public class Main { /** * create a new photo file on store card * @param subFolder * @param ext * @return */ public static File getNewFile(File subFolder, String ext) { int idx = 1; File file; do { file = new File(subFolder.getAbsolutePath() + String.format("/pics_%d" + ext, idx++)); } while (file.exists()); return file; } }