Android File Name Get appendNumberToFilenameIfExists(String fileName, File directory)

Here you can find the source of appendNumberToFilenameIfExists(String fileName, File directory)

Description

append Number To Filename If Exists

Declaration

public static File appendNumberToFilenameIfExists(String fileName,
            File directory) 

Method Source Code

//package com.java2s;

import java.io.File;

public class Main {
    public static File appendNumberToFilenameIfExists(String fileName,
            File directory) {/*from  www  . j  a va 2 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;
    }
}

Related

  1. getRandomFileName(String prefix, String suffix)
  2. parseFileName(String path)
  3. getSuffix(File file)
  4. getSuffix(String fileName)
  5. getNamePart(String fileName)
  6. getUniqueImageFilename(String prefix)
  7. getFileName()
  8. getFileName(String path)
  9. getFileNameFromURL(String url)