Here you can find the source of getRandomFilename(String prefix, String sufix)
Parameter | Description |
---|---|
prefix | can be "/tmp/tmpImage" |
sufix | typicaly - dot + extension ".bmp" |
public static synchronized String getRandomFilename(String prefix, String sufix)
//package com.java2s; import java.util.*; import java.io.*; public class Main { /** Returns the unique filename. * @param prefix can be "/tmp/tmpImage" * @param sufix typicaly - dot + extension ".bmp" * @return String filename, like "/tmp/tmpImage32397371.bmp" *///from w ww . ja va2 s. c om public static synchronized String getRandomFilename(String prefix, String sufix) { Random random = new Random(); int n = random.nextInt(); String res = prefix + Math.abs(n) + sufix; File file = new File(res); if (file.exists()) return getRandomFilename(prefix, sufix); else return res; } }