Here you can find the source of getTempFile(File file)
public static File getTempFile(File file) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.IOException; import java.util.Random; public class Main { private static final Random FILENAME_RANDOM = new Random(); /**/*from ww w . j a va 2s. com*/ * create a empty temp file at file's directory, temp file's name is based on file's name, i.e. * input "f1.txt", may output "f1.txt.tmp.467913456" */ public static File getTempFile(File file) throws IOException { File tempFile; while (true) { tempFile = new File(file.getParent(), file.getName() + ".tmp." + FILENAME_RANDOM.nextInt()); if (!tempFile.exists()) { if (!tempFile.createNewFile()) { throw new IOException(String.format("create %s failed", tempFile)); } return tempFile; } else continue; } } }