File.RenameTo(File) Method

Definition

Renames the file denoted by this abstract pathname.

[Android.Runtime.Register("renameTo", "(Ljava/io/File;)Z", "GetRenameTo_Ljava_io_File_Handler")]
public virtual bool RenameTo (Java.IO.File dest);
[<Android.Runtime.Register("renameTo", "(Ljava/io/File;)Z", "GetRenameTo_Ljava_io_File_Handler")>]
abstract member RenameTo : Java.IO.File -> bool
override this.RenameTo : Java.IO.File -> bool

Parameters

dest
File

The new abstract pathname for the named file

Returns

true if and only if the renaming succeeded; false otherwise

Attributes

Remarks

Renames the file denoted by this abstract pathname.

Many failures are possible. Some of the more likely failures include: <ul> <li>Write permission is required on the directories containing both the source and destination paths. <li>Search permission is required for all parents of both paths. <li>Both paths be on the same mount point. On Android, applications are most likely to hit this restriction when attempting to copy between internal storage and an SD card. </ul>

The return value should always be checked to make sure that the rename operation was successful.

Note that the java.nio.file.Files class defines the java.nio.file.Files#move move method to move or rename a file in a platform independent manner.

Java documentation for java.io.File.renameTo(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