HOME      BLOG       FORUMS      CONTACT       ABOUT

Renaming a file in Java

Renaming a file in Java

The renameTo method of file class can be used for renaming a file or directory.

import java.io.File;
/**
 * File class examples
 */
public class FileExample  {
	public static void main(String[] args){
		// Create file object representing the source file/directory
		File file = new File("d:\\temp\\test.txt");

		// Create the destination file/directory.
		File destintation = new File("d:\\temp\\test1.text");

		// Rename the file.
		boolean status = file.renameTo(destintation);

		System.out.println("Renaming status - "+status);

	}
}

Share

Tags: , , , ,


You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

AddThis Social Bookmark Button

Leave a Reply