find Unused File name - Android File Input Output

Android examples for File Input Output:File Name

Description

find Unused File name

Demo Code


//package com.java2s;
import java.io.File;

public class Main {
    public static File findUnusedFilename(File saveDirectory, String name,
            String extension) {/*  ww  w .  j  a v a  2  s  .c  o m*/
        File file;
        String str = "";
        int i = 0;
        do {
            file = new File(saveDirectory, name + str + extension);
            str = Integer.toString(i++);
        } while (file.exists());

        return file;
    }
}

Related Tutorials