Skip to Content

Create temporary file

  • 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
  3.   This Java example shows how to create a new temporary file using
  4.   createTempFile method of Java File class.
  5. */
  6.  
  7. import java.io.*;
  8.  
  9. public class CreateTemporaryFile {
  10.  
  11.   public static void main(String[] args) {
  12.    
  13.     /*
  14.      * To create temporary file use,
  15.      * static File createTempFile(String namePrefix, String nameSuffix) 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. Suffix
  21.      * may be null, and in that case default ".tmp" will be used as a suffix.
  22.      */
  23.    
  24.     File file1 = null;
  25.     File file2 = null;
  26.    
  27.     try
  28.     {
  29.       //create temporary file wihtout extension suffix
  30.       file1 = File.createTempFile("JavaTemp", null);
  31.      
  32.       //create temporary file with specified extension suffix
  33.       file2 = File.createTempFile("JavaTemp", ".javatemp");
  34.      
  35.     }
  36.     catch(IOException ioe)
  37.     {
  38.       System.out.println("Exception creating temporary file : " + ioe);
  39.     }
  40.    
  41.     /*
  42.      * Temporary file will be created in default temporary directory of operating
  43.      * system.
  44.      */
  45.     System.out.println("Temporary file without suffix extension: "
  46.                              + file1.getPath());
  47.     System.out.println("Temporary file with suffix extension: "
  48.                              + file2.getPath());
  49.    
  50.    
  51.   }
  52. }
  53.  
  54. /*
  55. Typical output would be
  56. Temporary file without suffix extension: C:\Temp\JavaTemp45096.tmp
  57. Temporary file with suffix extension: C:\Temp\JavaTemp45097.javatemp
  58. */