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


advertisement
 

Tip: Creating Temp Files Using Java

Learn how to create temporary files to perform certain actions.


advertisement

WEBINAR:

On-Demand

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


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

 

Visit the DevX Tip Bank

 





   
Sridhar M S. is a Java developer from Bangalore, India. He holds a master's degree in Computer Science.
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