Create temporary file with specified extension suffix
import java.io.File; public class Main { public static void main(String[] args) throws Exception { File file1 = null; File file2 = null; file1 = File.createTempFile("JavaTemp", null); file2 = File.createTempFile("JavaTemp", ".java"); System.out.println(file1.getPath()); System.out.println(file2.getPath()); } }