Android examples for File Input Output:File Name
append Number To Filename If Exists
//package com.java2s; import java.io.File; public class Main { public static File appendNumberToFilenameIfExists(String fileName, File directory) {//from ww w. ja v a2 s . c o m File newFile = new File(directory, fileName); int nextFile = 0; while (newFile.exists()) { nextFile++; newFile = new File(directory, fileName + " (" + Integer.toString(nextFile) + ")"); } return newFile; } }