The following example shows creating temp files in system temp directory as well as user
configured directory. The deleteOnExit method is a convenient method to delete unwanted
temporary files automatically when JVM exits.
//Creates a temp file in the given directory
tmpfile = File.createTempFile("mytempfile", ".txt", new File("C:\\NEW"));
tmpfile.deleteOnExit();
System.out.println(tmpfile.getAbsolutePath());
//Write to temp file
BufferedWriter writer = new BufferedWriter(new FileWriter(tmpfile));
writer.write("Hello World");
writer.close();