Here you can find the source of getRandomFileName(String prefix, String suffix)
Parameter | Description |
---|---|
prefix | the name of the file (sans extension) |
suffix | the extension of the file (including the '.') |
public static String getRandomFileName(String prefix, String suffix)
//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(); } }