Create temporary file
- /*
- Create temporary file
- This Java example shows how to create a new temporary file using
- createTempFile method of Java File class.
- */
- import java.io.*;
- public class CreateTemporaryFile {
- public static void main(String[] args) {
- /*
- * To create temporary file use,
- * static File createTempFile(String namePrefix, String nameSuffix) method
- * of Java File class,
- *
- * where namePrefix is a prefix string used to generate
- * a file's name and must be atleast 3 characters long and nameSuffix is a
- * suffix string used to generate suffix of the temporary file name. Suffix
- * may be null, and in that case default ".tmp" will be used as a suffix.
- */
- File file1 = null;
- File file2 = null;
- try
- {
- //create temporary file wihtout extension suffix
- file1 = File.createTempFile("JavaTemp", null);
- //create temporary file with specified extension suffix
- file2 = File.createTempFile("JavaTemp", ".javatemp");
- }
- catch(IOException ioe)
- {
- System.out.println("Exception creating temporary file : " + ioe);
- }
- /*
- * Temporary file will be created in default temporary directory of operating
- * system.
- */
- System.out.println("Temporary file without suffix extension: "
- + file1.getPath());
- System.out.println("Temporary file with suffix extension: "
- + file2.getPath());
- }
- }
- /*
- Typical output would be
- Temporary file without suffix extension: C:\Temp\JavaTemp45096.tmp
- Temporary file with suffix extension: C:\Temp\JavaTemp45097.javatemp
- */



