Home Tutorial Java Io Create a temporary file

 
 

Share on Google+Share on Google+
Create a temporary file
Posted on: February 17, 2011 at 12:00 AM
Advertisement
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

Advertisement

Related Tags for Create a temporary file:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: February 17, 2011

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com