File.CreateNewFile Method

Definition

Atomically creates a new, empty file named by this abstract pathname if and only if a file with this name does not yet exist.

[Android.Runtime.Register("createNewFile", "()Z", "GetCreateNewFileHandler")]
public virtual bool CreateNewFile ();
[<Android.Runtime.Register("createNewFile", "()Z", "GetCreateNewFileHandler")>]
abstract member CreateNewFile : unit -> bool
override this.CreateNewFile : unit -> bool

Returns

true if the named file does not exist and was successfully created; false if the named file already exists

Attributes

Exceptions

if it's not possible to create the file.

Remarks

Atomically creates a new, empty file named by this abstract pathname if and only if a file with this name does not yet exist. The check for the existence of the file and the creation of the file if it does not exist are a single operation that is atomic with respect to all other filesystem activities that might affect the file.

Note: this method should not be used for file-locking, as the resulting protocol cannot be made to work reliably. The java.nio.channels.FileLock FileLock facility should be used instead.

Added in 1.2.

Java documentation for java.io.File.createNewFile().

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