import java.io.File;
import java.io.IOException;
public class Utils {
/**
* Create a unique directory within a directory 'root'
*
* @param rootDir
* @param seed
* @return unique directory
* @throws IOException
*/
public static synchronized File createUniqueDirectory(File rootDir, String seed) throws IOException {
int index = seed.lastIndexOf('.');
if (index > 0) {
seed = seed.substring(0, index);
}
File result = null;
int count = 0;
while (result == null) {
String name = seed + "." + count + ".tmp";
File file = new File(rootDir, name);
if (!file.exists()) {
file.mkdirs();
result = file;
}
count++;
}
return result;
}
}
|