java2db

How to create a temp file in default or specified directory



To create a temp file in the default or specified directory, java.io.File provides a overloaded static method called createTempFile .

 

create a temp file in default or specified directory File.createTempFile(String prefix,String suffix)  : This method will take two parameters.

First parameter is the file name.

Second parameter is the extension (ex: “.temp ) or null .

 
File.createTempFile(String prefix,String suffix,File dir) : This method will take three parameters.

First parameter is the file name

Second parameter is the extension (ex: “.temp ) or null .

Third parameter is the  path/location.

 

Syntax:

File.createTempFile(<StringObjectFileName>,<StringObjectExtensionName>,<FileObjectSpecifiedPath>)

Example Code to create a temp file:

Execution Result:

 If we pass null instead of the File object ( createTempFile(prefix,suffix,null) )  , it will create a temp file in the  default temporary-file directory .




Related Posts :
what is directory and how to create distinguished name for LDAP
What is LDAP or Lightweight Directory Access Protocol
Get or Set Last Modified Date and Time for a File or directory in java
How to find all hidden files in a folder or directory in java
How to delete a file or folder from directory in java
How to rename a file from a directory or folder in java
How to get all file names from a directory or folder in java
   [will not be published]



^ <