Java File create temporary file in temporary directory
//package com.demo2s; import java.io.File; import java.util.UUID; public class Main { public static void main(String[] argv) throws Exception { System.out.println(aTempFile()); }/*from w w w . j a v a 2 s.co m*/ public static File aTempFile() { return removeableFile(tempFolder(), UUID.randomUUID().toString()); } private static File removeableFile(File folder, String fileName) { File file = new File(folder, fileName); file.deleteOnExit(); return file; } private static File tempFolder() { return new File(tempFolderName()); } private static String tempFolderName() { return System.getProperty("java.io.tmpdir"); } }