Rename a File in Java

Yes, you can simply use a text editor to rename a file. Or you could copy the file into a new location with a new name. But you also have the power to rename a file from within a Java program.

The File class has a renameTo() method.

Consider the following program:



Return to Unit Menu | | | Terms of Use  |

Notice: These materials are free for your on-line use at this site, but are not free for the taking.
Please do not copy these materials or re-post them to the Internet, as it is copyright infringement.
If you wish hard-copies of these materials, refer to our subscription area,
Help us keep these resources free. Thank you.