dcsimg
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Java
Expertise: Intermediate
Oct 29, 2018

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


Creating Temp Files Using Java

At times, you need to create temporary files to perform certain actions. The following code segment illustrates the same:

import java.io.*;

public class CreateTempFile
{
   public static void main(String args[])
   {
      CreateTempFile createTempFile = new CreateTempFile();
      createTempFile.proceed();
   }
   
   private void proceed()
   {
      try
      {
         File tempFile = File.createTempFile("FileNameStart",null); 
         //A new file with name FileNameStart.tmp will be created in the default Temp/tmp folder
         System.out.println("Temp file created and location is " + tempFile.getCanonicalPath());
      }catch(IOException ioe)
      {
         System.out.println("IOException: "+ioe);
      }
   }
}
M S Sridhar
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date