File class createTempFile(String prefix, String suffix, File directory) method example
Creates a new empty file in the specified directory
File class createTempFile(String prefix, String suffix, File directory)method example. This example shows you how to use createTempFile(String prefix, String suffix, File directory)method.This method Creates a new empty file in the specified directory, using the given prefix and suffix strings to generate its name.
Here is the code:-
/**
* @Program that Creates a new empty file in the specified directory,
* using the given prefix and suffix strings to generate its name.
* CreateTempFile1.java
* Author:-RoseIndia Team
* Date:-30-May-2008
*/
import java.io.*;
public class CreateTempFile1 {
public static void main(String[] args)throws IOException
{
//Creating file to the given location
File f=new File("/home/girish/Desktop");
//Creates a new empty file in the specified directory
File temp=f.createTempFile("rose",".tmp",f );
System.out.println("File Created Successfully");
}
} |
Output of the program:-
| File Created Successfully |
|