File class createTempFile(String prefix, String suffix)method example
Creates an empty file in the default temporary-file directory
File class createTempFile(String prefix, String suffix)method example. This example shows you how to use createTempFile(String prefix, String suffix)method.This method Creates an empty file in the default temporary-file directory, using the given prefix and suffix to generate its name.
Here is the code:-
/**
* @Program that Creates an empty file in the default temporary-file directory
using the given prefix and suffix to generate its name.
* CreateTempFile.java
* Author:-RoseIndia Team
* Date:-30-May-2008
*/
import java.io.*;
public class CreateTempFile {
public static void main(String[] args) throws IOException {
//Creating a file with given name and extension
File F = new File("girish", ".txt");
//Creates an empty file in the default temporary-file directory
File F1 = F.createTempFile("girish", ".txt");
System.out.println("Temperory File Created is in Location : " + F1.getAbsolutePath());
}
} |
Output of the program:-
| Temperory File Created is in Location : /tmp/girish26863.txt |
|