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: |
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.