Create temporary file in specified directory - Java File Path IO

Java examples for File Path IO:Temporary File

Description

Create temporary file in specified directory

Demo Code

import java.io.*;
 
public class Main {
 
  public static void main(String[] args) {
    File file = null;//from   w  w w  . j  av  a2s . c  o m
    File dir = new File("C://FileIO");
    try {
      file = File.createTempFile("JavaTemp", ".javatemp", dir);
    }
    catch(IOException ioe)
    {
    System.out.println("Exception creating temporary file : " + ioe);
    }
    System.out.println("Temporary file created at : " + file.getPath());
  }
}

Related Tutorials