Here you can find the source of getRelativeTemporaryFilename(String directory, String suffix, boolean autodelete)
static synchronized public String getRelativeTemporaryFilename(String directory, String suffix, boolean autodelete) throws IOException
//package com.java2s; /*/* ww w . ja va 2 s .c om*/ * Copyright (c) 2011, Marc R?ttig. * * This file is part of GenericKnimeNodes. * * GenericKnimeNodes is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ import java.io.File; import java.io.IOException; import java.util.Random; public class Main { static private Random rng = new Random(); static synchronized public String getRelativeTemporaryFilename(String directory, String suffix, boolean autodelete) throws IOException { int num = Math.abs(rng.nextInt()); File f = new File(directory + File.separator + String.format("%06d.%s", num, suffix)); while (f.exists()) { num = Math.abs(rng.nextInt()); f = new File(directory + File.separator + String.format("%06d.%s", num, suffix)); } f.createNewFile(); if (autodelete) f.deleteOnExit(); return f.getName(); } }