![]() |
VOOZH | about |
The createTempFile() function creates a temporary file in a given directory ( if directory is not mentioned then a default directory is selected ), the function generates the filename by using the prefix and suffix passed as the parameters . If the suffix is null then the function uses ".tmp" as suffix. The function then returns the created file
Function signature:
1. public static File createTempFile(String PREFIX, String SUFFIX)
OR
2. public static File createTempFile(String PREFIX, String SUFFIX, File DIR)
Syntax:
1. File.createTempFile(String, String, FILE); 2. File.createTempFile(String, String);
Parameters:The function is a overloaded function so one function takes suffix, prefix and a File object, whereas other function takes only suffix and prefix.The prefix must not be less than three characters but the suffix might be null and if the directory is not specified or a null value is passed then the function uses an default directory.
Return Type: The function returns the abstract file name denoting the newly created temporary file
Exception: This method throws:
Below programs illustrates the use of createTempFile() function:
Example 1: If we provide the prefix string and provide null suffix string
Output:
Temp File created: geeks7503529537487244659.tmp
Example 2: If we provide the prefix string and a definite suffix string
Output:
Temp File created: geeks4425780422923344328.SVP
Example 3: If we provide the prefix string, a definite suffix string and a directory
Output:
Temp File created: F:\geeks7006753451952178741.SVP
Note: The programs might not run in an online IDE. Please use an offline IDE and set the path of the file.