Create a temporary file

In this section, you will learn how to create a temporary file. This will perform with the help of createTempFile() method of File class.

 
 

Share on Google+Share on Google+

Create a temporary file

Ads

In this section, you will learn how to create a temporary file. This will perform with the help of createTempFile() method of File class.

Create a temporary file

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. 

Example :

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();
}

}

Output : 

temporary file created:                                               

Download Source Code

Advertisements

Ads

Posted on: February 17, 2011 If you enjoyed this post then why not add us on Google+? Add us to your Circles