Create temporary file in specified directory : Temporary File « File « Java Tutorial






import java.io.File;

public class Main {

  public static void main(String[] args) throws Exception {
    File file = null;
    File dir = new File("C:/");
    file = File.createTempFile("JavaTemp", ".javatemp", dir);

    System.out.println(file.getPath());

  }

}
//C:\JavaTemp5893283162648915021.javatemp








11.5.Temporary File
11.5.1.Create a temporary file
11.5.2.Create temporary file with specified extension suffix
11.5.3.Create temporary file in specified directory