How to create temporary file in Java
Published: June 4, 2010 , Updated: May 31, 2010 , Author: mkyong
Here’s an example to create a temporary file in Java.
Example
package com.mkyong.file; import java.io.File; import java.io.IOException; public class CreateTempFileExample { public static void main(String[] args) { try{ //create a temp file File temp = File.createTempFile("temp-file-name", ".tmp"); System.out.println("Temp file : " + temp.getAbsolutePath()); }catch(IOException e){ e.printStackTrace(); } } }
Result
Temp file : C:\Users\mkyong\AppData\Local\Temp\temp-file-name623426.tmp







Cool! Don’t know about this feature of File class.