Skip to Content

Create temporary file in specified directory

  • strict warning: Non-static method view::load() should not be called statically in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/views.module on line 906.
  • strict warning: Declaration of views_handler_argument::init() should be compatible with views_handler::init(&$view, $options) in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/handlers/views_handler_argument.inc on line 0.
  • strict warning: Declaration of views_handler_filter::options_validate() should be compatible with views_handler::options_validate($form, &$form_state) in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/handlers/views_handler_filter.inc on line 0.
  • strict warning: Declaration of views_handler_filter::options_submit() should be compatible with views_handler::options_submit($form, &$form_state) in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/handlers/views_handler_filter.inc on line 0.
  • strict warning: Declaration of views_handler_filter_boolean_operator::value_validate() should be compatible with views_handler_filter::value_validate($form, &$form_state) in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/handlers/views_handler_filter_boolean_operator.inc on line 0.
  • strict warning: Declaration of views_plugin_style_default::options() should be compatible with views_object::options() in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/plugins/views_plugin_style_default.inc on line 0.
  • strict warning: Declaration of views_plugin_row::options_validate() should be compatible with views_plugin::options_validate(&$form, &$form_state) in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/plugins/views_plugin_row.inc on line 0.
  • strict warning: Declaration of views_plugin_row::options_submit() should be compatible with views_plugin::options_submit(&$form, &$form_state) in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/plugins/views_plugin_row.inc on line 0.

  1. /*
  2.   Create temporary file in specified directory
  3.   This Java example shows how to create a new temporary file at specified path using
  4.   createTempFile method of Java File class.
  5. */
  6.  
  7. import java.io.*;
  8.  
  9. public class CreateTempFileDirectory {
  10.  
  11.   public static void main(String[] args) {
  12.    
  13.     /*
  14.      * To create temporary file at specified location use,
  15.      * static File createTempFile(String namePrefix, String nameSuffix, File dir) method
  16.      * of Java File class,
  17.      *
  18.      * where namePrefix is a prefix string used to generate
  19.      * a file's name and must be atleast 3 characters long and nameSuffix is a
  20.      * suffix string used to generate suffix of the temporary file name, may be null,
  21.      * and in that case default ".tmp" will be used as a suffix. dir is the
  22.      * directory under which the temporary file will be created.
  23.      */
  24.    
  25.     File file = null;
  26.     File dir = new File("C://FileIO");
  27.    
  28.     try
  29.     {
  30.       file = File.createTempFile("JavaTemp", ".javatemp", dir);
  31.     }
  32.     catch(IOException ioe)
  33.     {
  34.     System.out.println("Exception creating temporary file : " + ioe);
  35.     }
  36.  
  37.     /*
  38.      * Please note that if the directory does not exists, IOException will be
  39.      * thrown and temporary file will not be created.
  40.      */
  41.     System.out.println("Temporary file created at : " + file.getPath());
  42.   }
  43. }
  44.  
  45. /*
  46. Typical output would be
  47. Temporary file created at : C:\FileIO\JavaTemp40534.javatemp
  48. */