In this section, you will learn how to create a temporary file. This will perform with the help of createTempFile() method of File class.
In this section, you will learn how to create a temporary file. This will perform with the help of createTempFile() method of File class.In this section, you will learn how to create a temporary file. This will perform with the help of createTempFile() method of File class.
The syntax and description of createTempFile() method is given below :
public static File createTempFile(String prefix, String suffix) throws IOException
Description
This method creates an empty file in the default temporary-file directory, using the given prefix and suffix to generate its name.
package roseindia;
import java.io.*;
public class CreateTempFile {
public static void main(String[] args) throws Exception {
File temp = File.createTempFile("roseindia", ".tmp");
temp.deleteOnExit();
BufferedWriter out = new BufferedWriter(new FileWriter(temp));
out.write("Welcome to Roseindia");
System.out.println("temporary file created");
out.close();
}
}
| temporary file created: |