JAVA – Hot To Rename a File or Directory.

A quick script to re-name a file or folder:

Import required:

import java.io.File;

Code:

try{       
        // File name (or directory) of the file to be renamed
        File file = new File(“c:/file1.txt”);
        // New File name (or directory)
        File file2 = new File(“c:/file2.txt”);
        // Rename file (or directory)
        file.renameTo(file2);
    }catch(Exception e){
        e.printStackTrace();
    }

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s