Intro
To create a temporary file in Java, you can use createTempFile() method in the java.io.File class.
Example
package com.freesamplecode.java.io;
import java.io.File;
import java.io.IOException;
public class CreateTemporaryFileDemo {
public static void main(String[] args){
File tempFile = null;
try {
tempFile = File.createTempFile("tempfile", "tmp");
System.out.println("Successfully created temp file in "+tempFile.getAbsolutePath());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Output
Successfully created temp file in C:\Users\Dev\AppData\Local\Temp\tempfile5993040830414702074tmp
0 comments: