Home Tutorial Java Core Files Java file renameTo

 
 

Share on Google+Share on Google+
Java file renameTo
Posted on: June 10, 2006 at 12:00 AM
Advertisement
This section demonstrates you the use of renameTo method.

Java file renameTo

This section demonstrates you the use of renameTo method.

Description of code:

Java IO provides various useful tools that enables us to manipulate a file easily. By just using its built in methods, you can perform various file operations. The method renameTo() also belongs to this package. If you want to change the name of the file then you can use this method.

In the given example, we have created an object of File class and parse the file. Then we have called the method renameTo() through the object of File class. This method consists of a file object representing destination file,  and rename the specified file with this destination file.

Here is the code:

import java.io.*;

public class FileRename {
	public static void main(String[] args) {
		File f = new File("C:/filename.txt");
		f.renameTo(new File("C:/new.txt"));
	}
}

Through the method renameTo() , you can rename any file or directory. This method belongs to file class.

Advertisement

Related Tags for Java file renameTo:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: June 10, 2006

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com