Android File Name Get getRandomFileName(String prefix, String suffix)

Here you can find the source of getRandomFileName(String prefix, String suffix)

Description

Creates a file name with a random integer number inserted between the prefix and suffix

License

Open Source License

Parameter

Parameter Description
prefix the name of the file (sans extension)
suffix the extension of the file (including the '.')

Return

a new file name like test12534.txt

Declaration

public static String getRandomFileName(String prefix, String suffix) 

Method Source Code

//package com.java2s;
/**//  w  w  w.j a v a  2 s .  c  om
 * Aptana Studio
 * Copyright (c) 2005-2011 by Appcelerator, Inc. All Rights Reserved.
 * Licensed under the terms of the GNU Public License (GPL) v3 (with exceptions).
 * Please see the license.html included with this distribution for details.
 * Any modifications to this file must keep this entire header intact.
 */

public class Main {
    /**
     * Creates a file name with a random integer number inserted between the prefix and suffix
     * 
     * @param prefix
     *            the name of the file (sans extension)
     * @param suffix
     *            the extension of the file (including the '.')
     * @return a new file name like test12534.txt
     */
    public static String getRandomFileName(String prefix, String suffix) {
        StringBuilder name = new StringBuilder();
        if (prefix != null) {
            name.append(prefix);
        }
        name.append((long) (Integer.MAX_VALUE * Math.random()));
        if (suffix != null) {
            name.append(suffix);
        }
        return name.toString();
    }
}

Related

  1. getFileName(String fileName)
  2. getFileName(String filePath)
  3. getFileName(String path)
  4. parseFileName(String path)
  5. getSuffix(File file)
  6. getSuffix(String fileName)
  7. getNamePart(String fileName)