File.CreateTempFile Method

Definition

Overloads

CreateTempFile(String, String)

Creates an empty file in the default temporary-file directory, using the given prefix and suffix to generate its name.

CreateTempFile(String, String, File)

Creates a new empty file in the specified directory, using the given prefix and suffix strings to generate its name.

CreateTempFile(String, String)

Creates an empty file in the default temporary-file directory, using the given prefix and suffix to generate its name.

[Android.Runtime.Register("createTempFile", "(Ljava/lang/String;Ljava/lang/String;)Ljava/io/File;", "")]
public static Java.IO.File CreateTempFile (string prefix, string? suffix);
[<Android.Runtime.Register("createTempFile", "(Ljava/lang/String;Ljava/lang/String;)Ljava/io/File;", "")>]
static member CreateTempFile : string * string -> Java.IO.File

Parameters

prefix
String

The prefix string to be used in generating the file's name; must be at least three characters long

suffix
String

The suffix string to be used in generating the file's name; may be null, in which case the suffix ".tmp" will be used

Returns

An abstract pathname denoting a newly-created empty file

Attributes

Exceptions

if an error occurs when writing the file.

Remarks

Creates an empty file in the default temporary-file directory, using the given prefix and suffix to generate its name. Invoking this method is equivalent to invoking {@link #createTempFile(java.lang.String, java.lang.String, java.io.File) createTempFile(prefix,&nbsp;suffix,&nbsp;null)}.

The java.nio.file.Files#createTempFile(String,String,java.nio.file.attribute.FileAttribute[]) Files.createTempFile method provides an alternative method to create an empty file in the temporary-file directory. Files created by that method may have more restrictive access permissions to files created by this method and so may be more suited to security-sensitive applications.

Added in 1.2.

Java documentation for java.io.File.createTempFile(java.lang.String, java.lang.String).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

CreateTempFile(String, String, File)

Creates a new empty file in the specified directory, using the given prefix and suffix strings to generate its name.

[Android.Runtime.Register("createTempFile", "(Ljava/lang/String;Ljava/lang/String;Ljava/io/File;)Ljava/io/File;", "")]
public static Java.IO.File CreateTempFile (string prefix, string? suffix, Java.IO.File? directory);
[<Android.Runtime.Register("createTempFile", "(Ljava/lang/String;Ljava/lang/String;Ljava/io/File;)Ljava/io/File;", "")>]
static member CreateTempFile : string * string * Java.IO.File -> Java.IO.File

Parameters

prefix
String

The prefix string to be used in generating the file's name; must be at least three characters long

suffix
String

The suffix string to be used in generating the file's name; may be null, in which case the suffix ".tmp" will be used

directory
File

The directory in which the file is to be created, or null if the default temporary-file directory is to be used

Returns

An abstract pathname denoting a newly-created empty file

Attributes

Exceptions

if the length of prefix is less than 3.

if an error occurs when writing the file.

Remarks

Creates a new empty file in the specified directory, using the given prefix and suffix strings to generate its name. If this method returns successfully then it is guaranteed that:

<ol> <li> The file denoted by the returned abstract pathname did not exist before this method was invoked, and <li> Neither this method nor any of its variants will return the same abstract pathname again in the current invocation of the virtual machine. </ol>

This method provides only part of a temporary-file facility. To arrange for a file created by this method to be deleted automatically, use the {@link #deleteOnExit} method.

The prefix argument must be at least three characters long. It is recommended that the prefix be a short, meaningful string such as "hjb" or "mail". The suffix argument may be null, in which case the suffix ".tmp" will be used.

To create the new file, the prefix and the suffix may first be adjusted to fit the limitations of the underlying platform. If the prefix is too long then it will be truncated, but its first three characters will always be preserved. If the suffix is too long then it too will be truncated, but if it begins with a period character ('.') then the period and the first three characters following it will always be preserved. Once these adjustments have been made the name of the new file will be generated by concatenating the prefix, five or more internally-generated characters, and the suffix.

If the directory argument is null then the system-dependent default temporary-file directory will be used. The default temporary-file directory is specified by the system property java.io.tmpdir. On UNIX systems the default value of this property is typically "/tmp" or "/var/tmp"; on Microsoft Windows systems it is typically "C:\\WINNT\\TEMP". A different value may be given to this system property when the Java virtual machine is invoked, but programmatic changes to this property are not guaranteed to have any effect upon the temporary directory used by this method.

Added in 1.2.

Java documentation for java.io.File.createTempFile(java.lang.String, java.lang.String, java.io.File).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to